1313//===----------------------------------------------------------------------===//
1414
1515import Logging
16- import PostgresNIO
16+ public import PostgresNIO
1717
1818/// Database migration support
1919public actor DatabaseMigrations {
2020 enum State {
21- case waiting( [ CheckedContinuation < Void , Error > ] )
21+ case waiting( [ CheckedContinuation < Void , any Error > ] )
2222 case completed
23- case failed( Error )
23+ case failed( any Error )
2424 }
2525
26- var migrations : [ DatabaseMigration ]
27- var reverts : [ String : DatabaseMigration ]
26+ var migrations : [ any DatabaseMigration ]
27+ var reverts : [ String : any DatabaseMigration ]
2828 var state : State
2929
3030 /// Initialize a DatabaseMigrations object
@@ -38,7 +38,7 @@ public actor DatabaseMigrations {
3838 /// - Parameters
3939 /// - migration: DatabaseMigration to be applied
4040 /// - skipDuplicates: Only add migration if it doesn't exist in the list
41- public func add( _ migration: DatabaseMigration , skipDuplicates: Bool = false ) {
41+ public func add( _ migration: any DatabaseMigration , skipDuplicates: Bool = false ) {
4242 if skipDuplicates {
4343 let existingMigration = self . migrations. first {
4444 type ( of: $0) == type ( of: migration)
@@ -52,7 +52,7 @@ public actor DatabaseMigrations {
5252 ///
5353 /// This is useful for migrations you might have to revert.
5454 /// - Parameter migration: DatabaseMigration to be registerd
55- public func register( _ migration: DatabaseMigration ) {
55+ public func register( _ migration: any DatabaseMigration ) {
5656 self . reverts [ migration. name] = migration
5757 }
5858
@@ -96,7 +96,7 @@ public actor DatabaseMigrations {
9696 groups. count == 0
9797 ? ( migrations. map ( \. group) + appliedMigrations. map ( \. group) ) . uniqueElements
9898 : groups
99- var migrationsToApply : [ DatabaseMigration ] = . init( )
99+ var migrationsToApply : [ any DatabaseMigration ] = . init( )
100100 // for each group apply/revert migrations
101101 for group in groups {
102102 let groupMigrations = migrations. filter { $0. group == group }
@@ -180,7 +180,7 @@ public actor DatabaseMigrations {
180180 groups. count == 0
181181 ? ( migrations. map ( \. group) + appliedMigrations. map ( \. group) ) . uniqueElements
182182 : groups
183- var migrationsToRevert : [ DatabaseMigration ] = . init( )
183+ var migrationsToRevert : [ any DatabaseMigration ] = . init( )
184184 // for each group revert migrations
185185 for group in groups {
186186 let appliedGroupMigrations = appliedMigrations. filter { $0. group == group }
@@ -255,7 +255,7 @@ public actor DatabaseMigrations {
255255 // get migrations currently applied in the order they were applied
256256 let appliedMigrations = try await repository. getAll ( client: client, logger: logger)
257257
258- var migrationsToRevert : [ DatabaseMigration ] = . init( )
258+ var migrationsToRevert : [ any DatabaseMigration ] = . init( )
259259 // if groups array passed in is empty then work out list of migration groups by combining
260260 // list of groups from migrations and applied migrations
261261 let groups =
@@ -338,7 +338,7 @@ public actor DatabaseMigrations {
338338 }
339339 }
340340
341- func setFailed( _ error: Error ) {
341+ func setFailed( _ error: any Error ) {
342342 switch self . state {
343343 case . waiting( let continuations) :
344344 for cont in continuations {
@@ -437,14 +437,14 @@ struct PostgresMigrationRepository: Sendable {
437437 try await self . createMigrationsTable ( client: client, logger: logger)
438438 }
439439
440- func add( _ migration: DatabaseMigration , context: Context ) async throws {
440+ func add( _ migration: any DatabaseMigration , context: Context ) async throws {
441441 try await context. connection. query (
442442 " INSERT INTO _hb_pg_migrations ( \" name \" , \" group \" ) VALUES ( \( migration. name) , \( migration. group. name) ) " ,
443443 logger: context. logger
444444 )
445445 }
446446
447- func remove( _ migration: DatabaseMigration , context: Context ) async throws {
447+ func remove( _ migration: any DatabaseMigration , context: Context ) async throws {
448448 try await context. connection. query (
449449 " DELETE FROM _hb_pg_migrations WHERE name = \( migration. name) " ,
450450 logger: context. logger
0 commit comments