mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-22 04:00:39 +00:00
DatabaseMigrator is Sendable
This commit is contained in:
1 parent
6e691fe71d
commit
22114ad433
16 files changed
+22
-22
No files matched your search
@@ -40,7 +40,7 @@ import Foundation
|
||||
/// - ``completedMigrations(_:)``
|
||||
/// - ``hasBeenSuperseded(_:)``
|
||||
/// - ``hasCompletedMigrations(_:)``
|
||||
public struct DatabaseMigrator {
|
||||
public struct DatabaseMigrator: Sendable {
|
||||
/// Controls how a migration handle foreign keys constraints.
|
||||
public enum ForeignKeyChecks: Sendable {
|
||||
/// The migration runs with disabled foreign keys.
|
||||
@@ -207,7 +207,7 @@ public struct DatabaseMigrator {
|
||||
public mutating func registerMigration(
|
||||
_ identifier: String,
|
||||
foreignKeyChecks: ForeignKeyChecks = .deferred,
|
||||
migrate: @escaping (Database) throws -> Void)
|
||||
migrate: @escaping @Sendable (Database) throws -> Void)
|
||||
{
|
||||
let migrationChecks: Migration.ForeignKeyChecks
|
||||
switch foreignKeyChecks {
|
||||
@@ -264,7 +264,7 @@ public struct DatabaseMigrator {
|
||||
/// from succeeding.
|
||||
public func asyncMigrate(
|
||||
_ writer: some DatabaseWriter,
|
||||
completion: @escaping (Result<Database, Error>) -> Void)
|
||||
completion: @escaping @Sendable (Result<Database, Error>) -> Void)
|
||||
{
|
||||
writer.asyncBarrierWriteWithoutTransaction { dbResult in
|
||||
do {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/// An internal struct that defines a migration.
|
||||
struct Migration {
|
||||
struct Migration: Sendable {
|
||||
enum ForeignKeyChecks {
|
||||
case deferred
|
||||
case immediate
|
||||
@@ -8,7 +8,7 @@ struct Migration {
|
||||
|
||||
let identifier: String
|
||||
var foreignKeyChecks: ForeignKeyChecks
|
||||
let migrate: (Database) throws -> Void
|
||||
let migrate: @Sendable (Database) throws -> Void
|
||||
|
||||
func run(_ db: Database) throws {
|
||||
if try Bool.fetchOne(db, sql: "PRAGMA foreign_keys") ?? false {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
- [X] databasedatedecodingstrategy
|
||||
- [X] databasedateencodingstrategy
|
||||
- [X] databasefunction
|
||||
- [ ] databasemigrator
|
||||
- [X] databasemigrator
|
||||
- [ ] databasepublishers/databaseregion
|
||||
- [ ] databasepublishers/migrate
|
||||
- [ ] databasepublishers/read
|
||||
|
||||
@@ -128,7 +128,7 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
let expectation = self.expectation(description: "")
|
||||
migrator.asyncMigrate(writer, completion: { dbResult in
|
||||
migrator.asyncMigrate(writer, completion: { [migrator2] dbResult in
|
||||
// No migration error
|
||||
let db = try! dbResult.get()
|
||||
|
||||
@@ -795,13 +795,13 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.eraseDatabaseOnSchemaChange = true
|
||||
|
||||
var witness = 1
|
||||
let mutex = Mutex(0)
|
||||
migrator.registerMigration("1") { db in
|
||||
let value = mutex.increment()
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE t1(id INTEGER PRIMARY KEY);
|
||||
INSERT INTO t1(id) VALUES (?)
|
||||
""", arguments: [witness])
|
||||
witness += 1
|
||||
""", arguments: [value])
|
||||
}
|
||||
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
|
||||
@@ -15,7 +15,7 @@ private class Person : Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
@@ -13,7 +13,7 @@ private class MinimalNonOptionalPrimaryKeySingle: Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: "CREATE TABLE minimalSingles (id TEXT NOT NULL PRIMARY KEY)")
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class MinimalRowID : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: "CREATE TABLE minimalRowIDs (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class MinimalSingle: Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: "CREATE TABLE minimalSingles (UUID TEXT NOT NULL PRIMARY KEY)")
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ private class Person : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
creationDate TEXT NOT NULL,
|
||||
|
||||
@@ -14,7 +14,7 @@ private class Citizenship : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE citizenships (
|
||||
personName TEXT NOT NULL,
|
||||
|
||||
@@ -14,7 +14,7 @@ private class Item : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE items (
|
||||
name TEXT,
|
||||
|
||||
@@ -16,7 +16,7 @@ private class Person : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
@@ -12,7 +12,7 @@ class Pet : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE pets (
|
||||
UUID TEXT NOT NULL PRIMARY KEY,
|
||||
|
||||
@@ -11,7 +11,7 @@ class Email : Record, Hashable {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE emails (
|
||||
email TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE,
|
||||
|
||||
@@ -15,7 +15,7 @@ private class Person : Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: """
|
||||
CREATE TABLE persons (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
@@ -13,7 +13,7 @@ class BadlyMangledStuff : Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
static func setup(inDatabase db: Database) throws {
|
||||
@Sendable static func setup(inDatabase db: Database) throws {
|
||||
try db.execute(sql: "CREATE TABLE stuffs (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user