migrate(_:)
Runs all unapplied migrations, in the same order as they were registered.
func migrate(_ writer: any DatabaseWriter) throws
Parameters
- writer
A DatabaseWriter.
Throws
The error thrown by the first failed migration.
Runs all unapplied migrations, in the same order as they were registered.
func migrate(_ writer: any DatabaseWriter) throws
A DatabaseWriter.
The error thrown by the first failed migration.
import GRDB
A toolkit for SQLite databases, with a focus on application development
struct DatabaseMigrator
A DatabaseMigrator
registers and applies database migrations.
protocol DatabaseWriter : DatabaseReader
A type that writes into an SQLite database.
func asyncMigrate(_ writer: any DatabaseWriter, completion: @escaping (Result<Database, Error>) -> Void)
Schedules unapplied migrations for execution, and returns immediately.
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).
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 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.
mutating func registerMigration(_ identifier: String, foreignKeyChecks: ForeignKeyChecks = .deferred, migrate: @escaping (Database) throws -> Void)
Registers a migration.
enum ForeignKeyChecks
Controls how a migration handle foreign keys constraints.