-
I need to have a custom unique constraint - I'm trying to treat all return MigrationStrategy(
beforeOpen: (details) async {
if (kDebugMode) {
await validateDatabaseSchema();
}
await customStatement('PRAGMA foreign_keys = ON');
},
onCreate: (Migrator m) async {
await m.createAll();
await customStatement(
'CREATE UNIQUE INDEX IF NOT EXISTS UQ_PhysicalDevice ON "physical_devices" ("identifier", COALESCE("manufacturer", \'\'), "model_name");',
);
},
onUpgrade: upgradeStrategy,
); However, when running
For now, I've commented out the validation. Is there a way to tell the dart analyzer to expect the constraint? Or a more drift-friendly way to create it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You could add an index to the list of schema entities drift expects in the database by overriding this getter in the database class: @override
List<DatabaseSchemaEntity> get allSchemaEntities => [
...super.allSchemaEntities,
Index('UQ_PhysicalDevice',
'CREATE UNIQUE INDEX IF NOT EXISTS UQ_PhysicalDevice ON "physical_devices" ("identifier", COALESCE("manufacturer", \'\'), "model_name");')
]; This will also make the migrator create the index with |
Beta Was this translation helpful? Give feedback.
You could add an index to the list of schema entities drift expects in the database by overriding this getter in the database class:
This will also make the migrator create the index with
createAll()
, so you need no additional custom statements.