Skip to content

Commit

Permalink
Add revertLast
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jun 27, 2024
1 parent f8f6d43 commit 7630c61
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Sources/HummingbirdFluent/Fluent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public struct Fluent: Sendable, Service {

/// Manage Fluent database migrations
public actor FluentMigrations {
let migrations: Migrations
public let migrations: Migrations

init() {
self.migrations = .init()
Expand All @@ -106,6 +106,7 @@ public actor FluentMigrations {
/// - Parameters:
/// - migrations: Migrations array
/// - id: database id
@inlinable
public func add(_ migrations: [Migration], to id: DatabaseID? = nil) {
self.migrations.add(migrations, to: id)
}
Expand Down Expand Up @@ -139,4 +140,19 @@ public actor FluentMigrations {
try await migrator.setupIfNeeded().get()
try await migrator.revertAllBatches().get()
}

/// Revert last batch of fluent database migrations
/// - Parameters:
/// - databases: List of databases on which to revert migrations
/// - logger: Logger to use
func revertLast(databases: Databases, logger: Logger) async throws {
let migrator = Migrator(
databases: databases,
migrations: self.migrations,
logger: logger,
on: databases.eventLoopGroup.any()
)
try await migrator.setupIfNeeded().get()
try await migrator.revertLastBatch().get()
}
}

0 comments on commit 7630c61

Please sign in to comment.