Rename unsafeWithoutDeferredForeignKeyChecks to disablingDeferredForeignKeyChecks

This commit is contained in:
Gwendal Roué committed 2021-11-04 15:10:33 +01:00
1 parent d0997efbb6
commit 63ba4fb294
3 files changed
+14 -14

No files matched your search

+3 -3
View File
@@ -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
...
+4 -4
View File
@@ -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.
+7 -7
View File
@@ -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")
}