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 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:

dev_dependencies:
  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 with 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:

dependencies:
  drift: ^1.0.1
dev_dependencies:
  drift_dev: ^1.0.2

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
package:moor/extensions/json1.dartpackage:drift/extensions/json1.dart
package:moor/extensions/moor_ffi.dartpackage:drift/extensions/native.dart
package:moor/backends.dartpackage:drift/backends.dart
package:moor/ffi.dartpackage:drift/native.dart
package:moor/isolate.dartpackage:drift/isolate.dart
package:moor/moor_web.dartpackage:drift/web.dart
package:moor/moor.dartpackage:drift/drift.dart
package:moor/remote.dartpackage:drift/remote.dart
package:moor/sqlite_keywords.dartpackage:drift/sqlite_keywords.dart

Changing Dart code

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

Moor nameDrift name
VmDatabaseNativeDatabase
MoorIsolateDriftIsolate
MoorWebStorageDriftWebStorage
@UseMoor@DriftDatabase
@UseDao@DriftAccessor
MoorWrappedExceptionDriftWrappedException
MoorRuntimeOptionsDriftRuntimeOptions
moorRuntimeOptionsdriftRuntimeOptions
$mrjc and $mrjfUse Object.hash from dart:core
MoorServerDriftServer

(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
moor_generator|preparing_builderdrift_dev|preparing_builder
moor_generator|moor_generatordrift_dev|drift_dev
moor_generatordrift_dev
moor_generator|moor_generator_not_shareddrift_dev|not_shared
moor_generator|moor_cleanupdrift_dev|cleanup