Skip to content

Commit

Permalink
rename revert(_:) to register(_:)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Mar 14, 2024
1 parent ba6ff97 commit 563c586
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Sources/HummingbirdPostgres/Migrations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ public actor PostgresMigrations {
self.migrations.append(migration)
}

/// Add migration to list of reverts, that can be applied
/// - Parameter migration: Migration to be reverted if necessary
public func revert(_ migration: PostgresMigration) {
/// Register migration without it being applied
///
/// This is useful for migrations you might have to revert.
/// - Parameter migration: Migration to be registerd
public func register(_ migration: PostgresMigration) {
self.reverts[migration.name] = migration
}

Expand All @@ -68,7 +70,7 @@ public actor PostgresMigrations {
try await self.migrate(client: client, migrations: self.migrations, groups: groups, logger: logger, completeMigrations: true, dryRun: dryRun)
}

/// Revery database migrations
/// Revert database migrations
/// - Parameters:
/// - client: Postgres client
/// - logger: Logger to use
Expand Down
8 changes: 4 additions & 4 deletions Tests/HummingbirdPostgresTests/MigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ final class MigrationTests: XCTestCase {
try await self.testMigrations { migrations in
await migrations.add(TestMigration(name: "test1", order: order, applyOrder: 1))
await migrations.add(TestMigration(name: "test2", order: order, applyOrder: 2))
await migrations.revert(TestMigration(name: "test3", order: order, applyOrder: 3, revertOrder: 4))
await migrations.register(TestMigration(name: "test3", order: order, applyOrder: 3, revertOrder: 4))
} verify: { migrations, client in
try await migrations.apply(client: client, groups: [.default], logger: self.logger, dryRun: false)
let migrations = try await getAll(client: client)
Expand All @@ -198,7 +198,7 @@ final class MigrationTests: XCTestCase {
await migrations.add(TestMigration(name: "test1", order: order, applyOrder: 1))
await migrations.add(TestMigration(name: "test2", order: order, applyOrder: 2))
await migrations.add(TestMigration(name: "test4", order: order, applyOrder: 5))
await migrations.revert(TestMigration(name: "test3", order: order, applyOrder: 3, revertOrder: 4))
await migrations.register(TestMigration(name: "test3", order: order, applyOrder: 3, revertOrder: 4))
} verify: { migrations, client in
try await migrations.apply(client: client, groups: [.default], logger: self.logger, dryRun: false)
let migrations = try await getAll(client: client)
Expand Down Expand Up @@ -288,7 +288,7 @@ final class MigrationTests: XCTestCase {
// Remove migration from default group before the migration from the test group
try await self.testMigrations(groups: [.default, .test]) { migrations in
await migrations.add(TestMigration(name: "test1", order: order, applyOrder: 1, group: .default))
await migrations.revert(TestMigration(name: "test1_2", order: order, revertOrder: 4, group: .default))
await migrations.register(TestMigration(name: "test1_2", order: order, revertOrder: 4, group: .default))
await migrations.add(TestMigration(name: "test2", order: order, applyOrder: 2, group: .test))
} verify: { migrations, client in
try await migrations.apply(client: client, groups: [.default, .test], logger: self.logger, dryRun: false)
Expand Down Expand Up @@ -323,7 +323,7 @@ final class MigrationTests: XCTestCase {
XCTAssertEqual(migrations[1], "test2")
}
try await self.testMigrations(groups: [.default, .test]) { migrations in
await migrations.revert(TestMigration(name: "test2", order: order, applyOrder: 2, revertOrder: 4, group: .test))
await migrations.register(TestMigration(name: "test2", order: order, applyOrder: 2, revertOrder: 4, group: .test))
} verify: { _, _ in
}
order.expect(5)
Expand Down

0 comments on commit 563c586

Please sign in to comment.