diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index 192ab9294..875219d28 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -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 { + 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 { - 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] = []