mirror of https://github.com/AMT-Cheif/drift.git
44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:drift/drift.dart';
|
|
|
|
// #docregion
|
|
// import the migrations tooling
|
|
import 'package:drift_dev/api/migrations.dart';
|
|
// #enddocregion
|
|
|
|
const kDebugMode = true;
|
|
|
|
abstract class _$MyDatabase extends GeneratedDatabase {
|
|
_$MyDatabase(super.executor);
|
|
}
|
|
|
|
// #docregion
|
|
|
|
class MyDatabase extends _$MyDatabase {
|
|
// #enddocregion
|
|
MyDatabase(super.executor);
|
|
|
|
@override
|
|
Iterable<TableInfo<Table, dynamic>> get allTables =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
int get schemaVersion => throw UnimplementedError();
|
|
|
|
// #docregion
|
|
@override
|
|
MigrationStrategy get migration => MigrationStrategy(
|
|
onCreate: (m) async {/* ... */},
|
|
onUpgrade: (m, from, to) async {/* your existing migration logic */},
|
|
beforeOpen: (details) async {
|
|
// your existing beforeOpen callback, enable foreign keys, etc.
|
|
|
|
if (kDebugMode) {
|
|
// This check pulls in a fair amount of code that's not needed
|
|
// anywhere else, so we recommend only doing it in debug builds.
|
|
await validateDatabaseSchema();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
// #enddocregion
|