ForeignKeyChecks
Controls how a migration handle foreign keys constraints.
enum ForeignKeyChecks
Controls how a migration handle foreign keys constraints.
enum ForeignKeyChecks
import GRDB
A toolkit for SQLite databases, with a focus on application development
struct DatabaseMigrator
A DatabaseMigrator
registers and applies database migrations.
case deferred
The migration runs with disabled foreign keys.
case immediate
The migration runs with enabled foreign keys.
mutating func registerMigration(_ identifier: String, foreignKeyChecks: ForeignKeyChecks = .deferred, migrate: @escaping (Database) throws -> Void)
Registers a migration.
init()
A new migrator.
var eraseDatabaseOnSchemaChange: Bool
A boolean value indicating whether the migrator recreates the whole database from scratch if it detects a change in the definition of migrations.
var migrations: [String] { get }
The list of registered migration identifiers, in the same order as they have been registered.
func appliedIdentifiers(_ db: Database) throws -> Set<String>
Returns the applied migration identifiers, even unregistered ones.
func appliedMigrations(_ db: Database) throws -> [String]
Returns the identifiers of registered and applied migrations, in the order of registration.
func asyncMigrate(_ writer: any DatabaseWriter, completion: @escaping (Result<Database, Error>) -> Void)
Schedules unapplied migrations for execution, and returns immediately.
func completedMigrations(_ db: Database) throws -> [String]
Returns the identifiers of registered and completed migrations, in the order of registration.
func disablingDeferredForeignKeyChecks() -> DatabaseMigrator
Returns a migrator that disables foreign key checks in all newly registered migrations.
func hasBeenSuperseded(_ db: Database) throws -> Bool
A boolean value indicating whether the database refers to unregistered migrations.
func hasCompletedMigrations(_ db: Database) throws -> Bool
A boolean value indicating whether all registered migrations, and only registered migrations, have been applied.
func hasSchemaChanges(_ db: Database) throws -> Bool
Returns a boolean value indicating whether the migrator detects a change in the definition of migrations.
func migrate(_ writer: any DatabaseWriter) throws
Runs all unapplied migrations, in the same order as they were registered.
func migrate(_ writer: any DatabaseWriter, upTo targetIdentifier: String) throws
Runs all unapplied migrations, in the same order as they were registered, up to the target migration identifier (included).
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.