drift
drift copied to clipboard
Unable to migrate moor to drift
Got lot of issues when run dart run moor_generator migrate
PS C:\Users\nick_\xxx> dart run moor_generator migrate
Resolving dependencies in `C:\Users\nick_\xxx`... (5.3s)
Downloading packages... (2.3s)
Got dependencies in `C:\Users\nick_\xxx`.
Building package executable... (19.7s)
Failed to build moor_generator:moor_generator:
../AppData/Local/Pub/Cache/hosted/pub.dev/moor_generator-4.6.0+1/bin/moor_generator.dart:1:1: Error: The specified language version is too low. The lowest supported language version is 2.12.
//@dart=2.9
^^^^^^^^^^^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/cli/cli.dart:1:1: Error: The specified language version is too low. The lowest supported language version is 2.12.
//@dart=2.9
...
../AppData/Local/Pub/Cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
abstract class _ConstructableFileSystemEvent implements FileSystemEvent {
^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/backends/common/driver.dart:30:15: Error: The parameter 'contextRoot' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
{String contextRoot,
^^^^^^^^^^^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/backends/common/driver.dart:31:14: Error: The parameter 'sdkPath' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
String sdkPath,
^^^^^^^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/cli/logging.dart:5:47: Error: The parameter 'useAnsi' can't have a value of 'null' because of its type 'bool', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
void setupLogging({bool verbose = false, bool useAnsi}) {
^^^^^^^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/cli/commands/identify_databases.dart:42:39: Error: Property 'fromClass' cannot be accessed on 'DatabaseOrDaoDeclaration?' because it is potentially null.
- 'DatabaseOrDaoDeclaration' is from 'package:drift_dev/src/model/declarations/declaration.dart' ('../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/model/declarations/declaration.dart').
Try accessing using ?. instead.
.map((t) => t.declaration.fromClass.name)
^^^^^^^^^
../AppData/Local/Pub/Cache/hosted/pub.dev/drift_dev-1.0.2/lib/src/cli/commands/migrate.dart:120:50: Error: Prop
pubspec.yaml
dependencies:
flutter:
sdk: flutter
dartx: ^1.0.0
...
moor_flutter: ^4.0.0
moor: ^4.6.1+1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.2
build_runner: ^2.1.7
...
moor_generator: ^4.6.0+1
Flutter version
Flutter 3.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ee4e09cce0 (2 years, 9 months ago) • 2022-05-09 16:45:18 -0700
Engine • revision d1b9a6938a
Tools • Dart 2.17.0 • DevTools 2.12.2
Tools • Dart 2.17.0 • DevTools 2.12.2
That Dart version should actually be able to run pre-NNBD code. The minimum language version was raised to 2.12 in Dart 3.0 if I remember correctly. Does running dart --version print the same 2.17.0 version or is there another Dart installation that you might be running instead?
Anyway, could you remove moor_generator from your pubspec and replace the dependency with drift_dev? The current version of drift_dev is 2.25.0, but you'll likely need an older version since you also have an old Flutter version. Try using drift_dev: ^2.0.0 and see if pub get works.
Once you have drift_dev, you should still be able to migrate by running dart run drift_dev migrate.
Because drift_dev >=2.0.0 <2.1.0 depends on drift >=2.0.0 <2.1.0 and drift_dev >=2.1.0 <2.2.0+1 depends on drift >=2.0.0 <2.2.0, drift_dev >=2.0.0 <2.2.0+1 requires drift >=2.0.0 <2.2.0.
And because drift_dev >=2.2.0+1 <2.3.0 depends on drift >=2.0.0 <2.3.0, drift_dev >=2.0.0 <2.3.0 requires drift >=2.0.0 <2.3.0.
And because drift_dev >=2.3.0 <2.4.0 depends on drift >=2.3.0 <2.4.0 and drift_dev >=2.4.0 <2.10.0 depends on string_scanner ^1.1.1, drift_dev >=2.0.0 <2.10.0 requires drift >=2.0.0 <2.3.0 or >=2.3.0 <2.4.0 or string_scanner ^1.1.1.
And because moor >=4.6.0 depends on drift ^1.0.0 and drift_dev >=2.10.0 requires SDK version >=3.0.0 <4.0.0, if moor >=4.6.0 and drift_dev >=2.0.0 then string_scanner ^1.1.1.
And because every version of flutter_test from sdk depends on string_scanner 1.1.0 and xxx depends on moor ^4.6.1+1, drift_dev >=2.0.0 is incompatible with flutter_test from sdk.
So, because xxx depends on both flutter_test from sdk and drift_dev ^2.0.0, version solving failed.
pub get failed (1; So, because xxx depends on both flutter_test from sdk and drift_dev ^2.0.0, version solving failed.)
exit code 1
I need change drift as well?
I need change
driftas well?
That might break the automated migration script. If you leave version 1 of drift (obtained through moor), can you add this to your pubspec and see if it works?
dependency_overrides:
drift_dev: ^2.0.0
environment:
sdk: ">=2.15.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dartx: ^1.0.0
drift_sqflite: ^1.0.0
analyzer: 5.5.0
drift: ^1.0.0
dependency_overrides:
firebase_core_platform_interface: ^4.5.1
collection: ^1.17.0
drift_dev: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.2
build_runner: ^2.1.7
Error
PS C:\Users\nick_\xxx> fvm flutter --version
Flutter 3.0.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ee4e09cce0 (2 years, 9 months ago) • 2022-05-09 16:45:18 -0700
Engine • revision d1b9a6938a
Tools • Dart 2.17.0 • DevTools 2.12.2
PS C:\Users\nick_\xxx> fvm flutter pub get
Running "flutter pub get" in xxx...
Because drift_dev >=2.0.0 <2.2.0+1 depends on analyzer ^4.5.0 and drift_dev >=2.2.0+1 <2.3.0 depends on drift >=2.0.0 <2.3.0, drift_dev >=2.0.0 <2.3.0 requires analyzer ^4.5.0 or drift >=2.0.0 <2.3.0.
And because drift_dev >=2.3.0 <2.4.0 depends on drift >=2.3.0 <2.4.0 and drift_dev >=2.4.0 <2.23.0 depends on string_scanner ^1.1.1, drift_dev >=2.0.0 <2.23.0 requires drift >=2.0.0 <2.3.0 or >=2.3.0 <2.4.0 or analyzer ^4.5.0 or string_scanner ^1.1.1.
And because drift_dev >=2.23.0 depends on string_scanner ^1.2.0 and every version of flutter_test from sdk depends on string_scanner 1.1.0, if drift_dev >=2.0.0 and flutter_test from sdk then drift >=2.0.0 <2.3.0 or >=2.3.0 <2.4.0 or analyzer ^4.5.0.
And because xxx depends on both analyzer 5.5.0 and drift ^1.0.0, drift_dev >=2.0.0 is incompatible with flutter_test from sdk.
So, because xxx depends on both flutter_test from sdk and drift_dev ^2.0.0, version solving failed.
pub get failed (1; So, because xxxdepends on both flutter_test from sdk and drift_dev ^2.0.0, version solving failed.)
PS C:\Users\nick_\xxx>
This resolves for me, but I don't know if the automated migration will work with that state:
environment:
sdk: ">=2.15.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dartx: ^1.0.0
drift_sqflite: ^2.0.0
analyzer: 5.5.0
moor: ^4.0.0
# drift: ^1.0.0
dependency_overrides:
firebase_core_platform_interface: ^4.5.1
collection: ^1.17.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.2
build_runner: ^2.1.7
drift_dev: ^2.0.0
drift: any
Alternativey, you could also take a look at the manual migration steps, it's not that much work.
Hi, thanks for your solution. I use it, and it works. However, when I run build_runner, I still get a lot of errors.
I manually change moor to drift, changing Dart imports and Dart code, update flutter to latest version, now hitting this
PS C:\Users\nick_\xxx> fvm flutter packages pub run build_runner build --delete-conflicting-outputs
Can't load Kernel binary: Invalid kernel binary format version.
Deprecated. Use `dart run` instead.
[INFO] Generating build script completed, took 680ms
[INFO] Reading cached asset graph completed, took 1.8s
[INFO] Checking for updates since last build completed, took 7.6s
[WARNING] No actions completed for 30.3s, waiting on:
- json_serializable on test/widget_test.dart
- json_serializable on lib/bloc/clock_in_bloc.dart
- json_serializable on lib/bloc/defect_bloc.dart
...
.. and 11 more
[SEVERE] json_serializable on lib/data/db/abc_db.dart:
line 1, column 80638 of package:xxx/data/db/abc_db.dart: Could not resolve annotation for `class ABCDb`.
╷
1 │ ┌ @DriftDatabase(tables: [
2 │ │ UserTable,
3 │ │ WorkOrders,
4 │ │ CategoryOne,
5 │ │ CategoryTwo,
...
[WARNING] drift_dev on lib/data/db/abc_dao.dart:
line 93, column 7 of package:xxx/data/db/abc_dao.dart: The referenced element, WorkOrders, is not understood by drift.
╷
93 │ class ABCDao extends DatabaseAccessor<ABCDb> with _$ABCDaoMixin {
│ ^^^^^^^^^^
╵
[WARNING] drift_dev on lib/data/db/abc_dao.dart:
line 93, column 7 of package:abc/data/db/abc_dao.dart: The referenced element, CategoryOne, is not understood by drift.
╷
Any clue?
Are there any analyzer errors reported on that code? Any warnings about unresolved references perhaps? If we can't resolve annotations, it's probably because the annotation references a class that doesn't exist.