mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Documentation
This commit is contained in:
1 parent
ed6ad9d373
commit
cff769ddd5
1 file changed
+22
-18
@@ -170,8 +170,10 @@ public struct DatabaseMigrator {
|
||||
|
||||
// MARK: - Querying Migrations
|
||||
|
||||
/// Returns the applied migration identifiers, in the same order as
|
||||
/// registered migrations.
|
||||
/// Returns the identifiers of registered and applied migrations, in the
|
||||
/// order of registration.
|
||||
///
|
||||
/// See also `appliedIdentifiers(_:)`.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: An eventual database error.
|
||||
@@ -180,6 +182,24 @@ public struct DatabaseMigrator {
|
||||
return migrations.map { $0.identifier }.filter { appliedIdentifiers.contains($0) }
|
||||
}
|
||||
|
||||
/// Returns the applied migration identifiers, even unregistered ones.
|
||||
///
|
||||
/// See also `appliedMigrations(_:)`.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: An eventual database error.
|
||||
public func appliedIdentifiers(_ db: Database) throws -> Set<String> {
|
||||
do {
|
||||
return try Set(String.fetchCursor(db, sql: "SELECT identifier FROM grdb_migrations"))
|
||||
} catch {
|
||||
// Rethrow if we can't prove grdb_migrations does not exist yet
|
||||
if (try? !db.tableExists("grdb_migrations")) ?? false {
|
||||
return []
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the identifiers of completed migrations, of which all previous
|
||||
/// migrations have been applied.
|
||||
///
|
||||
@@ -222,22 +242,6 @@ public struct DatabaseMigrator {
|
||||
migrations.append(migration)
|
||||
}
|
||||
|
||||
/// Returns the applied migration identifiers, even unregistered ones
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: An eventual database error.
|
||||
public func appliedIdentifiers(_ db: Database) throws -> Set<String> {
|
||||
do {
|
||||
return try Set(String.fetchCursor(db, sql: "SELECT identifier FROM grdb_migrations"))
|
||||
} catch {
|
||||
// Rethrow if we can't prove grdb_migrations does not exist yet
|
||||
if (try? !db.tableExists("grdb_migrations")) ?? false {
|
||||
return []
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns unapplied migration identifier,
|
||||
private func unappliedMigrations(upTo targetIdentifier: String, appliedIdentifiers: [String]) -> [Migration] {
|
||||
var expectedMigrations: [Migration] = []
|
||||
|
||||
Reference in new issue
Block a user