registerMigrationWithDisabledForeignKeyChecks documentation

This commit is contained in:
Gwendal Roué committed 2016-05-17 20:12:20 +02:00
1 parent c1169f0d2c
commit ea2f202e4d
1 file changed
+2 -2
+2 -2
View File
@@ -2215,11 +2215,11 @@ try migrator.migrate(dbQueue) // or migrator.migrate(dbPool)
SQLite does not support many schema changes, and won't let you drop a table column with "ALTER TABLE ... DROP COLUMN ...", for example.
Yet any kind of schema change is still possible. The SQLite documentation explains in detail how to do so: https://www.sqlite.org/lang_altertable.html#otheralter. This technique requires the temporary disabling of foreign key checks, and is supported by the `withDisabledForeignKeyChecks` argument:
Yet any kind of schema change is still possible. The SQLite documentation explains in detail how to do so: https://www.sqlite.org/lang_altertable.html#otheralter. This technique requires the temporary disabling of foreign key checks, and is supported by the `registerMigrationWithDisabledForeignKeyChecks` function:
```swift
// Add a NOT NULL constraint on persons.name:
migrator.registerMigration("AddNotNullCheckOnName", withDisabledForeignKeyChecks: true) { db in
migrator.registerMigrationWithDisabledForeignKeyChecks("AddNotNullCheckOnName") { db in
try db.execute(
"CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT NOT NULL);" +
"INSERT INTO new_persons SELECT * FROM persons;" +