@@ -37,31 +37,13 @@ extension Database {
37
37
let runAt : Date ?
38
38
}
39
39
40
- /// Applies all outstanding migrations to the database in a single
41
- /// batch. Migrations are read from `database.migrations`.
42
- public func migrate( ) async throws {
43
- let applied = try await getAppliedMigrations ( ) . map ( \. name)
44
- let toApply = migrations. filter { !applied. contains ( $0. name) }
45
- try await migrate ( toApply)
46
- }
47
-
48
- /// Rolls back all migrations from all batches.
49
- public func reset( ) async throws {
50
- try await rollback ( getAppliedMigrations ( ) . reversed ( ) )
51
- }
52
-
53
- /// Rolls back the latest migration batch.
54
- public func rollback( ) async throws {
55
- let lastBatch = try await getLastBatch ( )
56
- let migrations = try await getAppliedMigrations ( batch: lastBatch, enforceRegistration: true )
57
- try await rollback ( migrations. reversed ( ) )
58
- }
40
+ /// Applies the provided migrations or all outstanding migrations to the
41
+ /// database in a single batch. Migrations are read from
42
+ /// `database.migrations`.
43
+ public func migrate( _ migrations: [ Migration ] ? = nil ) async throws {
44
+ let appliedMigrations = try await getAppliedMigrations ( ) . map ( \. name)
45
+ let migrations = ( migrations ?? self . migrations) . filter { !appliedMigrations. contains ( $0. name) }
59
46
60
- /// Run the `.up` functions of an array of migrations in order.
61
- ///
62
- /// - Parameters:
63
- /// - migrations: The migrations to apply to this database.
64
- public func migrate( _ migrations: [ Migration ] ) async throws {
65
47
guard !migrations. isEmpty else {
66
48
Log . info ( " Nothing to migrate. " . green)
67
49
return
@@ -77,6 +59,18 @@ extension Database {
77
59
}
78
60
}
79
61
62
+ /// Rolls back all migrations from all batches.
63
+ public func reset( ) async throws {
64
+ try await rollback ( getAppliedMigrations ( ) . reversed ( ) )
65
+ }
66
+
67
+ /// Rolls back the latest migration batch.
68
+ public func rollback( ) async throws {
69
+ let lastBatch = try await getLastBatch ( )
70
+ let migrations = try await getAppliedMigrations ( batch: lastBatch, enforceRegistration: true )
71
+ try await rollback ( migrations. reversed ( ) )
72
+ }
73
+
80
74
/// Run the `.down` functions of an array of migrations, in order.
81
75
///
82
76
/// - Parameter migrations: The migrations to rollback on this
0 commit comments