Documentation

This commit is contained in:
Gwendal Roué committed 2020-05-11 08:54:31 +02:00
1 parent ed6ad9d373
commit cff769ddd5
1 file changed
+22 -18
+22 -18
View File
@@ -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] = []