Reset schema when validateDatabaseSchema()
fails
#2684
Answered
by
simolus3
hiroshihorie
asked this question in
Q&A
-
I use Drift as a local cache for my app and I can afford to clear / recreate all data when schema changes. |
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Oct 18, 2023
Replies: 1 comment 7 replies
-
Something like this in the }, beforeOpen: (details) async {
try {
await validateDatabaseSchema();
} on SchemaMismatch {
// Delete all databases and re-create
final migrator = createMigrator();
final reversedEntities = allSchemaEntities.toList().reversed;
for (final entity in reversedEntities) {
await migrator.drop(entity);
}
await migrator.createAll();
}
}); You don't need an |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
hiroshihorie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this in the
MigrationStrategy
should work:You don't need an
onUpgrade
callback at all in that case.