mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Rename DatabaseMigrator.registerMigrationWithDisabledForeignKeyChecks to registerMigrationWithDeferredForeignKeyCheck
This commit is contained in:
1 parent
fa464b489d
commit
deebf289de
5 files changed
+17
-9
No files matched your search
@@ -1,6 +1,14 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
## Next version
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- `DatabaseMigrator.registerMigrationWithDisabledForeignKeyChecks` has been renamed `DatabaseMigrator.registerMigrationWithDeferredForeignKeyCheck` ([documentation](https://github.com/groue/GRDB.swift#advanced-database-schema-changes))
|
||||
|
||||
|
||||
|
||||
## 0.101.1
|
||||
|
||||
Released January 20, 2017
|
||||
|
||||
@@ -65,7 +65,7 @@ public struct DatabaseMigrator {
|
||||
/// Registers an advanced migration, as described at https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
///
|
||||
/// // Add a NOT NULL constraint on persons.name:
|
||||
/// migrator.registerMigrationWithDisabledForeignKeyChecks("AddNotNullCheckOnName") { db in
|
||||
/// migrator.registerMigrationWithDeferredForeignKeyCheck("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;" +
|
||||
@@ -81,7 +81,7 @@ public struct DatabaseMigrator {
|
||||
/// - identifier: The migration identifier.
|
||||
/// - block: The migration block that performs SQL statements.
|
||||
/// - precondition: No migration with the same same as already been registered.
|
||||
public mutating func registerMigrationWithDisabledForeignKeyChecks(_ identifier: String, migrate: @escaping (Database) throws -> Void) {
|
||||
public mutating func registerMigrationWithDeferredForeignKeyCheck(_ identifier: String, migrate: @escaping (Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disabledForeignKeyChecks: true, migrate: migrate))
|
||||
}
|
||||
#else
|
||||
@@ -89,7 +89,7 @@ public struct DatabaseMigrator {
|
||||
/// Registers an advanced migration, as described at https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
///
|
||||
/// // Add a NOT NULL constraint on persons.name:
|
||||
/// migrator.registerMigrationWithDisabledForeignKeyChecks("AddNotNullCheckOnName") { db in
|
||||
/// migrator.registerMigrationWithDeferredForeignKeyCheck("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;" +
|
||||
@@ -105,7 +105,7 @@ public struct DatabaseMigrator {
|
||||
/// - identifier: The migration identifier.
|
||||
/// - block: The migration block that performs SQL statements.
|
||||
/// - precondition: No migration with the same same as already been registered.
|
||||
public mutating func registerMigrationWithDisabledForeignKeyChecks(_ identifier: String, migrate: @escaping (Database) throws -> Void) {
|
||||
public mutating func registerMigrationWithDeferredForeignKeyCheck(_ identifier: String, migrate: @escaping (Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disabledForeignKeyChecks: true, migrate: migrate))
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3412,11 +3412,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 `registerMigrationWithDisabledForeignKeyChecks` function:
|
||||
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 `registerMigrationWithDeferredForeignKeyCheck` function:
|
||||
|
||||
```swift
|
||||
// Add a NOT NULL constraint on persons.name:
|
||||
migrator.registerMigrationWithDisabledForeignKeyChecks("AddNotNullCheckOnName") { db in
|
||||
migrator.registerMigrationWithDeferredForeignKeyCheck("AddNotNullCheckOnName") { db in
|
||||
try db.create(table: "new_persons") { t in
|
||||
t.column("id", .integer).primaryKey()
|
||||
t.column("name", .text).notNull()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- [ ] registerMigrationWithDisabledForeignKeyChecks should be renamed registerMigrationWithDeferredForeignKeyChecks
|
||||
- [X] registerMigrationWithDisabledForeignKeyChecks should be renamed registerMigrationWithDeferredForeignKeyCheck
|
||||
- [ ] Enable extended result codes (https://github.com/groue/GRDB.swift/issues/171)
|
||||
- [ ] Request.fetchCount() (see https://github.com/groue/GRDB.swift/issues/176#issuecomment-282783884). This method should be a customization point, not an extension.
|
||||
- [ ] Check that https://github.com/groue/GRDB.swift/issues/172#issuecomment-282511719 is true (manual deferred foreign key check)
|
||||
|
||||
@@ -145,14 +145,14 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
let personId = db.lastInsertedRowID
|
||||
try db.execute("INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId])
|
||||
}
|
||||
migrator.registerMigrationWithDisabledForeignKeyChecks("removePersonTmpColumn") { db in
|
||||
migrator.registerMigrationWithDeferredForeignKeyCheck("removePersonTmpColumn") { db in
|
||||
// Test the technique described at https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
try db.execute("CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute("INSERT INTO new_persons SELECT id, name FROM persons")
|
||||
try db.execute("DROP TABLE persons")
|
||||
try db.execute("ALTER TABLE new_persons RENAME TO persons")
|
||||
}
|
||||
migrator.registerMigrationWithDisabledForeignKeyChecks("foreignKeyError") { db in
|
||||
migrator.registerMigrationWithDeferredForeignKeyCheck("foreignKeyError") { db in
|
||||
// Make sure foreign keys are checked at the end.
|
||||
try db.execute("INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
do {
|
||||
|
||||
Reference in new issue
Block a user