mirror of https://github.com/AMT-Cheif/drift.git
Fix example snippet
This commit is contained in:
parent
def066ad26
commit
c3d2065d96
|
@ -168,7 +168,7 @@ extension StepByStep2 on GeneratedDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StepByStep3 on GeneratedDatabase {
|
extension StepByStep3 on Example {
|
||||||
MigrationStrategy get migration {
|
MigrationStrategy get migration {
|
||||||
return MigrationStrategy(
|
return MigrationStrategy(
|
||||||
onCreate: (Migrator m) async {
|
onCreate: (Migrator m) async {
|
||||||
|
@ -180,26 +180,25 @@ extension StepByStep3 on GeneratedDatabase {
|
||||||
// (https://drift.simonbinder.eu/docs/advanced-features/migrations/#tips)
|
// (https://drift.simonbinder.eu/docs/advanced-features/migrations/#tips)
|
||||||
await customStatement('PRAGMA foreign_keys = OFF');
|
await customStatement('PRAGMA foreign_keys = OFF');
|
||||||
|
|
||||||
|
// Manually running migrations up to schema version 2, after which we've
|
||||||
|
// enabled step-by-step migrations.
|
||||||
if (from < 2) {
|
if (from < 2) {
|
||||||
// we added the dueDate property in the change from version 1 to
|
// we added the dueDate property in the change from version 1 to
|
||||||
// version 2
|
// version 2 - before switching to step-by-step migrations.
|
||||||
await m.addColumn(schema.todos, schema.todos.dueDate);
|
await m.addColumn(todos, todos.dueDate);
|
||||||
}
|
|
||||||
|
|
||||||
if (from < 3) {
|
|
||||||
// we added the priority property in the change from version 1 or 2
|
|
||||||
// to version 3
|
|
||||||
await m.addColumn(schema.todos, schema.todos.priority);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, we should be migrated to schema 3. For future schema
|
// At this point, we should be migrated to schema 3. For future schema
|
||||||
// changes, we will "start" at schema 3.
|
// changes, we will "start" at schema 3.
|
||||||
await m.runMigrationSteps(
|
await m.runMigrationSteps(
|
||||||
from: math.max(3, from),
|
from: math.max(2, from),
|
||||||
to: to,
|
to: to,
|
||||||
|
// ignore: missing_required_argument
|
||||||
steps: migrationSteps(
|
steps: migrationSteps(
|
||||||
from3To4: (m, schema) async {
|
from2To3: (m, schema) async {
|
||||||
// Perform schema migrations for schema 4
|
// we added the priority property in the change from version 1 or
|
||||||
|
// 2 to version 3
|
||||||
|
await m.addColumn(schema.todos, schema.todos.priority);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -207,10 +207,10 @@ This allows you to perform all prior migration work to get the database to the "
|
||||||
|
|
||||||
{% include "blocks/snippet" snippets = snippets name = 'stepbystep3' %}
|
{% include "blocks/snippet" snippets = snippets name = 'stepbystep3' %}
|
||||||
|
|
||||||
Here, we give a "floor" to the `from` value of `3`, since we've performed all other migration work to get to
|
Here, we give a "floor" to the `from` value of `2`, since we've performed all other migration work to get to
|
||||||
this point. From now on, you can generate step-by-step migrations for each schema change.
|
this point. From now on, you can generate step-by-step migrations for each schema change.
|
||||||
|
|
||||||
If you did not do this, a user migrating from schema 1 directly to schema 4 would not properly walk migrations
|
If you did not do this, a user migrating from schema 1 directly to schema 3 would not properly walk migrations
|
||||||
and apply all migration changes required.
|
and apply all migration changes required.
|
||||||
|
|
||||||
### Writing tests
|
### Writing tests
|
||||||
|
|
Loading…
Reference in New Issue