1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import Foundation
16-
1715import App
1816import PostgresNIO
1917import ShellOut
@@ -22,10 +20,7 @@ import Vapor
2220
2321
2422actor DatabasePool {
25- typealias DatabaseID = UUID
26-
2723 struct Database : Hashable {
28- var id : DatabaseID
2924 var port : Int
3025
3126 var connectionDetails : ConnectionDetails {
@@ -98,20 +93,19 @@ actor DatabasePool {
9893 }
9994
10095 private func launchDB( maxAttempts: Int = 3 ) async throws -> Database {
101- let id = UUID ( )
10296 let port = Int . random ( in: 10_000 ... 65_000 )
103- _ = try ? await ShellOut . shellOut ( to: . removeDB( id : id ) )
97+ _ = try ? await ShellOut . shellOut ( to: . removeDB( port : port ) )
10498 try await run ( maxAttempts: 3 ) { attempt in
105- print ( " ⚠️ Launching DB \( id ) on port \( port) (attempt: \( attempt) ) " )
106- try await ShellOut . shellOut ( to: . launchDB( id : id , port: port) )
99+ print ( " ⚠️ Launching DB on port \( port) (attempt: \( attempt) ) " )
100+ try await ShellOut . shellOut ( to: . launchDB( port: port) )
107101 }
108- return . init( id : id , port: port)
102+ return . init( port: port)
109103 }
110104
111105 private func removeDB( database: Database , maxAttempts: Int = 3 ) async throws {
112106 try await run ( maxAttempts: 3 ) { attempt in
113- // print("⚠️ Removing DB \(database.id) on port \(database.port) (attempt: \(attempt))")
114- try await ShellOut . shellOut ( to: . removeDB( id : database. id ) )
107+ // print("⚠️ Removing DB on port \(database.port) (attempt: \(attempt))")
108+ try await ShellOut . shellOut ( to: . removeDB( port : database. port ) )
115109 }
116110 }
117111}
0 commit comments