migration property
override
Defines the migration strategy that will determine how to deal with an increasing schemaVersion. The default value only supports creating the database by creating all tables known in this database. When you have changes in your schema, you'll need a custom migration strategy to create the new tables or change the columns.
Implementation
@override
MigrationStrategy get migration {
return MigrationStrategy(
onUpgrade: (m, b, a) async {
Log.info('MigrationStrategy.onUpgrade($a, $b)', '$runtimeType');
if (_closed) {
return;
}
// TODO: Implement proper migrations.
if (a != b) {
if (a >= 2 && b <= 1) {
await m.addColumn(users, users.welcomeMessage);
}
}
await m.createAll();
},
beforeOpen: (_) async {
Log.debug('MigrationStrategy.beforeOpen()', '$runtimeType');
if (_closed) {
return;
}
try {
await customStatement('PRAGMA foreign_keys = ON;');
// Note, that WAL doesn't work in Web:
// https://github.com/simolus3/sqlite3.dart/issues/200
await customStatement('PRAGMA journal_mode = WAL;');
} catch (e) {
Log.error('Custom SQL statement has failed: $e', '$runtimeType');
}
},
);
}