From 63ba4fb294543521fdccca2cb3021356d2c92679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 4 Nov 2021 15:10:33 +0100 Subject: [PATCH] Rename unsafeWithoutDeferredForeignKeyChecks to disablingDeferredForeignKeyChecks --- Documentation/Migrations.md | 6 +++--- GRDB/Migration/DatabaseMigrator.swift | 8 ++++---- Tests/GRDBTests/DatabaseMigratorTests.swift | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index f3ee41b39..dc04387ad 100644 --- a/Documentation/Migrations.md +++ b/Documentation/Migrations.md @@ -185,7 +185,7 @@ You can ask the migrator to stop performing foreign key checks for all newly reg :warning: If you use this technique, your app becomes responsible for preventing foreign key violations from being committed to disk! ```swift -migrator = migrator.unsafeWithoutDeferredForeignKeyChecks() +migrator = migrator.disablingDeferredForeignKeyChecks() // From now on, migrations are unchecked! migrator.registerMigration("fast but unchecked") { db in ... } @@ -196,7 +196,7 @@ In order to prevent foreign key violations from being committed to disk, you can - Run migrations with immediate foreign key check, as long as they do not require the technique described by [Making Other Kinds Of Table Schema Changes](https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes): ```swift - migrator = migrator.unsafeWithoutDeferredForeignKeyChecks() + migrator = migrator.disablingDeferredForeignKeyChecks() migrator.registerMigration("unchecked") { db in ... } migrator.registerMigration("checked", foreignKeyChecks: .immediate) { db in ... } ``` @@ -204,7 +204,7 @@ In order to prevent foreign key violations from being committed to disk, you can - Perform foreign key checks on some tables only: ```swift - migrator = migrator.unsafeWithoutDeferredForeignKeyChecks() + migrator = migrator.disablingDeferredForeignKeyChecks() migrator.registerMigration("partially checked") { db in ... diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index 6c967e4c7..52f55892d 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -53,7 +53,7 @@ public struct DatabaseMigrator { /// are checked right before changes are committed on disk. /// /// These deferred checks are not executed if the migrator comes - /// from `unsafeWithoutDeferredForeignKeyChecks()`. + /// from `disablingDeferredForeignKeyChecks()`. /// /// Deferred foreign key checks are necessary for migrations that /// perform schema changes as described in @@ -122,7 +122,7 @@ public struct DatabaseMigrator { /// // Runs with immediate foreign key checks /// } /// - /// migrator = migrator.unsafeWithoutDeferredForeignKeyChecks() + /// migrator = migrator.disablingDeferredForeignKeyChecks() /// migrator.registerMigration("C") { db in /// // Runs with disabled foreign key checks /// } @@ -133,7 +133,7 @@ public struct DatabaseMigrator { /// - warning: Before using this unsafe method, try to run your migrations with /// `.immediate` foreign key checks, if possible. This may enhance migration /// performances, while preserving the database integrity guarantee. - public func unsafeWithoutDeferredForeignKeyChecks() -> DatabaseMigrator { + public func disablingDeferredForeignKeyChecks() -> DatabaseMigrator { with { $0.defersForeignKeyChecks = false } } @@ -158,7 +158,7 @@ public struct DatabaseMigrator { /// disabled foreign keys, until foreign keys are checked right before /// changes are committed on disk. These deferred checks are not /// executed if the migrator comes - /// from `unsafeWithoutDeferredForeignKeyChecks()`. + /// from `disablingDeferredForeignKeyChecks()`. /// /// The `.immediate` checks have the migration run with foreign /// keys enabled. diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index 7e9befa09..cdae329fc 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -920,7 +920,7 @@ class DatabaseMigratorTests : GRDBTestCase { } } - func testUnsafeWithoutDeferredForeignKeyChecks() throws { + func testDisablingDeferredForeignKeyChecks() throws { let foreignKeyViolation = """ CREATE TABLE parent(id INTEGER NOT NULL PRIMARY KEY); CREATE TABLE child(parentId INTEGER REFERENCES parent(id)); @@ -935,7 +935,7 @@ class DatabaseMigratorTests : GRDBTestCase { // Foreign key violation do { - var migrator = DatabaseMigrator().unsafeWithoutDeferredForeignKeyChecks() + var migrator = DatabaseMigrator().disablingDeferredForeignKeyChecks() migrator.registerMigration("A") { db in try db.execute(sql: foreignKeyViolation) } @@ -947,7 +947,7 @@ class DatabaseMigratorTests : GRDBTestCase { } } do { - var migrator = DatabaseMigrator().unsafeWithoutDeferredForeignKeyChecks() + var migrator = DatabaseMigrator().disablingDeferredForeignKeyChecks() migrator.registerMigration("A", foreignKeyChecks: .immediate) { db in try db.execute(sql: foreignKeyViolation) } @@ -963,7 +963,7 @@ class DatabaseMigratorTests : GRDBTestCase { // Transient foreign key violation do { - var migrator = DatabaseMigrator().unsafeWithoutDeferredForeignKeyChecks() + var migrator = DatabaseMigrator().disablingDeferredForeignKeyChecks() migrator.registerMigration("A") { db in try db.execute(sql: transientForeignKeyViolation) } @@ -974,7 +974,7 @@ class DatabaseMigratorTests : GRDBTestCase { } } do { - var migrator = DatabaseMigrator().unsafeWithoutDeferredForeignKeyChecks() + var migrator = DatabaseMigrator().disablingDeferredForeignKeyChecks() migrator.registerMigration("A", foreignKeyChecks: .immediate) { db in try db.execute(sql: transientForeignKeyViolation) } @@ -989,7 +989,7 @@ class DatabaseMigratorTests : GRDBTestCase { } } - func testUnsafeWithoutDeferredForeignKeyChecks_applies_to_newly_registered_migrations() throws { + func test_disablingDeferredForeignKeyChecks_applies_to_newly_registered_migrations_only() throws { let foreignKeyViolation = """ CREATE TABLE parent(id INTEGER NOT NULL PRIMARY KEY); CREATE TABLE child(parentId INTEGER REFERENCES parent(id)); @@ -1000,7 +1000,7 @@ class DatabaseMigratorTests : GRDBTestCase { migrator.registerMigration("A") { db in try db.execute(sql: foreignKeyViolation) } - migrator = migrator.unsafeWithoutDeferredForeignKeyChecks() + migrator = migrator.disablingDeferredForeignKeyChecks() migrator.registerMigration("B") { db in XCTFail("Should not run") }