Moor and Drift

Information about the name change from moor to drift

Moor has been renamed to drift. The reason for this is that, in some parts of the world, moor may be used as a derogatory term. I have not been aware of this when starting this project, but we believe that the current name does not reflect the inclusivity of the Dart and Flutter communities. Despite the associated effort, I'm convinced that renaming the project is the right decision. Thank you for your understanding!

Until version 5.0.0, the current moor, moor_flutter and moor_generator packages will continue to work - no urgent action is necessary. All features and fixes to the new drift packages will be mirrored in moor as well. At the next breaking release, the moor set of packages will be discontinued in favor of drift and drift_dev.

This page describes how to migrate from the old moor package to the new drift package. This process can be automated, and we hope that the migration is a matter of minutes for you. In case of issues with the tool, this page also describes how to manually migrate to the new drift packages.

Automatic migration

To make the name change as easy as possible for you, drift comes with an automatic migration tool for your project. It will analyze your source files and perform all changes that come with this migration.

To use the migration tool, please first make sure that you're using moor_generator version 4.6.0 or later, for instance by updating your dependency on it:

  moor_generator: ^4.6.0

Next, please make sure that your project does not contain analysis errors, as this could make the migration tool less effective. Also, please create a backup of your project's files before running the migration tool. It will override parts of your sources without further confirmation. When using git, it is sufficient to ensure that you have a clean state.

To apply the migration, run dart run moor_generator migrate in your project's directory. When using Flutter, run flutter pub run moor_generator migrate instead. The migration tool will transform your pubspec, build.yaml files and Dart source files. It will also rename .moor files to .drift and patch imports as needed.

After running the migration, please verify the changes to ensure that they match what you expect. Also, you may have to

  • Format your sources again: Run dart format . or flutter format .
  • Re-run the build: Run dart run build_runner build or flutter pub run build_runner build --delete-conflicting-outputs, respectively.
  • Manually fix the changed order of imports caused by the migration.

Congratulations, your project is now using drift!

If you run into any issues with the automatic migration tool, please open an issue.

Manual migration

To migrate from moor to drift, you may have to update:

  • Your pubspec
  • Dart imports
  • Dart code, to reflect new API names
  • Your build.yaml configuration files, if any

The following sections will describe each of the steps.

New dependencies

First, replace the moor dependency with drift and moor_generator with drift_dev, respectively:

  drift: ^1.7.1
  drift_dev: ^1.7.0

If you've been using moor_flutter, also add a dependency on drift_sqflite: ^1.0.0.

Run pub get to get the new packages.

Changing Dart imports

This table compares the old imports from moor and the new imports for drift:

Moor importDrift import

Changing Dart code

This table compares old moor-specific API names and new names as provided by drift:

Moor nameDrift name
$mrjc and $mrjfUse Object.hash from dart:core

(Optional: Rename moor files)

For consistency, you can rename your .moor files to .drift. The drift generator will continue to accept .moor files though.

If you opt for a rename, also update your imports and include: parameters in database and DAO classes.

Build configuration

When configuring moor builders for options, you have to update your build.yaml files to reflect the new builder keys:

Moor builder keyDrift builder key