diff --git a/Sources/FluentKit/Enum/EnumMetadata.swift b/Sources/FluentKit/Enum/EnumMetadata.swift index b6430e99..78c397e4 100644 --- a/Sources/FluentKit/Enum/EnumMetadata.swift +++ b/Sources/FluentKit/Enum/EnumMetadata.swift @@ -26,9 +26,9 @@ final class EnumMetadata: Model, @unchecked Sendable { } } -private struct EnumMetadataMigration: AsyncMigration { - func prepare(on database: any Database) async throws { - try await database.schema(EnumMetadata.schema) +private struct EnumMetadataMigration: Migration { + func prepare(on database: any Database) -> EventLoopFuture { + database.schema(EnumMetadata.schema) .id() .field("name", .string, .required) .field("case", .string, .required) @@ -37,7 +37,7 @@ private struct EnumMetadataMigration: AsyncMigration { .create() } - func revert(on database: any Database) async throws { - try await database.schema(EnumMetadata.schema).delete() + func revert(on database: any Database) -> EventLoopFuture { + database.schema(EnumMetadata.schema).delete() } } diff --git a/Sources/FluentKit/Migration/MigrationLog.swift b/Sources/FluentKit/Migration/MigrationLog.swift index d2e8302f..9529123a 100644 --- a/Sources/FluentKit/Migration/MigrationLog.swift +++ b/Sources/FluentKit/Migration/MigrationLog.swift @@ -6,7 +6,7 @@ public final class MigrationLog: Model, @unchecked Sendable { public static let schema = "_fluent_migrations" public static var migration: any Migration { - return MigrationLogMigration() + MigrationLogMigration() } @ID(key: .id) @@ -35,9 +35,9 @@ public final class MigrationLog: Model, @unchecked Sendable { } } -private struct MigrationLogMigration: AsyncMigration { - func prepare(on database: any Database) async throws { - try await database.schema(MigrationLog.schema) +private struct MigrationLogMigration: Migration { + func prepare(on database: any Database) -> EventLoopFuture { + database.schema(MigrationLog.schema) .field(.id, .uuid, .identifier(auto: false)) .field("name", .string, .required) .field("batch", .int, .required) @@ -48,7 +48,7 @@ private struct MigrationLogMigration: AsyncMigration { .create() } - func revert(on database: any Database) async throws { - try await database.schema(MigrationLog.schema).delete() + func revert(on database: any Database) -> EventLoopFuture { + database.schema(MigrationLog.schema).delete() } } diff --git a/Sources/FluentKit/Migration/Migrator.swift b/Sources/FluentKit/Migration/Migrator.swift index 02755015..f40ac046 100644 --- a/Sources/FluentKit/Migration/Migrator.swift +++ b/Sources/FluentKit/Migration/Migrator.swift @@ -113,20 +113,20 @@ public struct Migrator: Sendable { private func migrators( _ handler: (DatabaseMigrator) -> EventLoopFuture ) -> EventLoopFuture<[Result]> { - self.migrations.storage.withLockedValue { $0.map { + self.migrations.storage.withLockedValue { $0 }.map { handler(.init(id: $0, database: self.databaseFactory($0), migrations: $1, migrationLogLevel: self.migrationLogLevel)) - } } + } .flatten(on: self.eventLoop) } } private final class DatabaseMigrator: Sendable { let migrations: [any Migration] - let database: any Database & Sendable + let database: any Database let id: DatabaseID? let migrationLogLevel: Logger.Level - init(id: DatabaseID?, database: any Database & Sendable, migrations: [any Migration], migrationLogLevel: Logger.Level) { + init(id: DatabaseID?, database: any Database, migrations: [any Migration], migrationLogLevel: Logger.Level) { self.migrations = migrations self.database = database self.id = id @@ -172,11 +172,11 @@ private final class DatabaseMigrator: Sendable { } func revertBatch(number: Int) -> EventLoopFuture { - self.preparedMigrations(batch: number).sequencedFlatMapEach(self.revert) + self.preparedMigrations(batch: number).sequencedFlatMapEach { self.revert($0) } } func revertAllBatches() -> EventLoopFuture { - self.preparedMigrations().sequencedFlatMapEach(self.revert) + self.preparedMigrations().sequencedFlatMapEach { self.revert($0) } } // MARK: Preview