diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed8a8f4c..06027304f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/GRDB/Migrations/DatabaseMigrator.swift b/GRDB/Migrations/DatabaseMigrator.swift index c938bf713..7f5f82250 100644 --- a/GRDB/Migrations/DatabaseMigrator.swift +++ b/GRDB/Migrations/DatabaseMigrator.swift @@ -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 diff --git a/README.md b/README.md index 403c2d53a..6eb809c34 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/TODO.md b/TODO.md index 9b8408aad..5d1b56480 100644 --- a/TODO.md +++ b/TODO.md @@ -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) diff --git a/Tests/Public/Migrations/DatabaseMigratorTests.swift b/Tests/Public/Migrations/DatabaseMigratorTests.swift index 06ff9e81f..9092a3d9f 100644 --- a/Tests/Public/Migrations/DatabaseMigratorTests.swift +++ b/Tests/Public/Migrations/DatabaseMigratorTests.swift @@ -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 {