-
IssueMigration does not seem to run. Even logging statements are not appearing in console. BackgroundBeen deleting the DB and restarting from scratch. The app (Flutter iOS/Android) is now live and I would like to avoid forcing users to reinstall from scratch. So, I followed the "Getting Started" migrations guide.
@override
MigrationStrategy get migration {
Logger.info("LocalDb: In migration");
return MigrationStrategy(
beforeOpen: (details) async {
await customStatement(
'PRAGMA foreign_keys=1; PRAGMA trusted_schema=1;');
},
onUpgrade: (m, from, to) async {
Logger.info("LocalDb: In onUpgrade $from to $to");
await m.runMigrationSteps(
from: from,
to: to,
steps: migrationSteps(
from1To2: (m, schema) async {
Logger.info("LocalDb: In steps $from to $to");
await customStatement(diff1To2);
},
),
);
},
);
}
// ...
const diff1To2 = """
PRAGMA trusted_schema=1;
CREATE TABLE IF NOT EXISTS notes (
row_id INTEGER PRIMARY KEY AUTOINCREMENT,
note_id VARCHAR(36) NOT NULL UNIQUE,
title VARCHAR(127),
body TEXT NOT NULL,
logged_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
);
CREATE VIRTUAL TABLE IF NOT EXISTS notes_search USING fts5(
title,
body,
content='notes',
content_rowid='row_id',
);
CREATE TRIGGER IF NOT EXISTS notes_ai AFTER INSERT ON notes BEGIN
INSERT INTO notes_search(rowid, title, body) VALUES (new.row_id, new.title, new.body);
END;
CREATE TRIGGER IF NOT EXISTS notes_au AFTER UPDATE ON notes BEGIN
DELETE FROM notes_search WHERE rowid = old.row_id;
INSERT INTO notes_search(rowid, title, body) VALUES (new.row_id, new.title, new.body);
END;
CREATE TRIGGER IF NOT EXISTS notes_ad AFTER DELETE ON notes BEGIN
DELETE FROM notes_search WHERE rowid = old.row_id;
END;
"""; Other informationVersions are: drift: ^2.21.0 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Drift uses the Depending on whether the app was running when you wrote the migration code, there's a chance that (e.g. due to a hot restart) the database was restarted with unfinished migration code which upgraded the That said, if the database works it's likely that the migration simply ran already, which is why it wouldn't run again? |
Beta Was this translation helpful? Give feedback.
-
Edit: Oddly, I can create it if I connect to the SQLite DB and manually paste the statement, but the Could the problem be the FTS table? My build.yaml is as follows: targets:
$default:
builders:
drift_dev:
options:
databases:
my_database: lib/services/drift/local_database.dart
store_date_time_values_as_text: true
sql:
dialects:
- sqlite
options:
modules:
- fts5
Moreover, the error when attempting to insert is:
Finally, when I uninstall the app completely (assumingely deleting the SQLite DB with it), the only log statement that I can see in console is "In migration". The other statements with Edit: For some reason, both |
Beta Was this translation helpful? Give feedback.
Latest edit: Sorry to bother you, this issue was apparently caused by a trailing comma in the
notes_search
table.It is using
drift_flutter: ^0.2.0
for a Flutter app on iOS and Android.I can create the
fts5
table when I download the data container using Xcode or connect to the DB on the simulator using something likesqlite3 path/to/local_db.db
but that is probably irrelevant here since it uses my laptop's version of SQLite3 as opposed to the one thatdrift_flutter
comes with?Thanks for the tip on checking pragmas via
customSelect
--both of them were actually enabled.Edit: Logged out
final q3 = await (localDb.customSelect('PRAGMA compile_options')).get();
andflutter: {compile_options:…