Skip to content

Commit fd57101

Browse files
authored
Adopt Async Shutdown (#221)
* Drop support for Swift 5.8 * Update dependencies * Adopt new APIs * Fix some warnings in Swift 6 * Update CI
1 parent e2988a8 commit fd57101

File tree

7 files changed

+26
-59
lines changed

7 files changed

+26
-59
lines changed

.github/workflows/test.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ jobs:
4545
- postgres-image-a: 'postgres:13'
4646
postgres-image-b: 'postgres:14'
4747
postgres-auth: 'trust'
48-
swift-image: 'swift:5.8-focal'
48+
swift-image: 'swift:5.9-focal'
4949
- postgres-image-a: 'postgres:15'
5050
postgres-image-b: 'postgres:16'
5151
postgres-auth: 'md5'
5252
swift-image: 'swift:5.10-jammy'
5353
- postgres-image-a: 'postgres:15'
5454
postgres-image-b: 'postgres:16'
5555
postgres-auth: 'scram-sha-256'
56-
swift-image: 'swiftlang/swift:nightly-6.0-jammy'
56+
swift-image: 'swift:6.0-jammy'
5757
container: ${{ matrix.swift-image }}
5858
runs-on: ubuntu-latest
5959
services:
@@ -89,8 +89,6 @@ jobs:
8989
fail-fast: false
9090
matrix:
9191
include:
92-
- macos-version: macos-13
93-
xcode-version: '~14.3'
9492
- macos-version: macos-14
9593
xcode-version: latest
9694
runs-on: ${{ matrix.macos-version }}

Package.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44
let package = Package(
@@ -13,8 +13,8 @@ let package = Package(
1313
.library(name: "FluentPostgresDriver", targets: ["FluentPostgresDriver"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
17-
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
16+
.package(url: "https://github.com/vapor/async-kit.git", from: "1.20.0"),
17+
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.49.0"),
1818
.package(url: "https://github.com/vapor/postgres-kit.git", from: "2.13.4"),
1919
],
2020
targets: [
@@ -40,6 +40,9 @@ let package = Package(
4040
)
4141

4242
var swiftSettings: [SwiftSetting] { [
43+
.enableUpcomingFeature("ExistentialAny"),
4344
.enableUpcomingFeature("ConciseMagicFile"),
4445
.enableUpcomingFeature("ForwardTrailingClosures"),
46+
.enableUpcomingFeature("DisableOutwardActorInference"),
47+
.enableExperimentalFeature("StrictConcurrency=complete"),
4548
] }

[email protected]

-48
This file was deleted.

Sources/FluentPostgresDriver/FluentPostgresDriver.swift

+4
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ struct _FluentPostgresDriver<E: PostgresJSONEncoder, D: PostgresJSONDecoder>: Da
2727
func shutdown() {
2828
try? self.pool.syncShutdownGracefully()
2929
}
30+
31+
func shutdownAsync() async {
32+
try? await self.pool.shutdownAsync()
33+
}
3034
}

Sources/FluentPostgresDriver/PostgresError+Database.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ fileprivate extension PostgresError.Code {
7171
}
7272
}
7373

74-
extension PostgresError: DatabaseError {
74+
// Used for DatabaseError conformance
75+
extension PostgresError {
7576
public var isSyntaxError: Bool { self.code.isSyntaxError }
7677
public var isConnectionClosed: Bool {
7778
switch self {
@@ -82,7 +83,8 @@ extension PostgresError: DatabaseError {
8283
public var isConstraintFailure: Bool { self.code.isConstraintFailure }
8384
}
8485

85-
extension PSQLError: DatabaseError {
86+
// Used for DatabaseError conformance
87+
extension PSQLError {
8688
public var isSyntaxError: Bool {
8789
switch self.code {
8890
case .server: return self.serverInfo?[.sqlState].map { PostgresError.Code(raw: $0).isSyntaxError } ?? false
@@ -104,3 +106,11 @@ extension PSQLError: DatabaseError {
104106
}
105107
}
106108
}
109+
110+
#if compiler(<6)
111+
extension PostgresError: DatabaseError { }
112+
extension PSQLError: DatabaseError { }
113+
#else
114+
extension PostgresError: @retroactive DatabaseError { }
115+
extension PSQLError: @retroactive DatabaseError { }
116+
#endif

Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ final class FluentPostgresDriverTests: XCTestCase {
274274
}
275275

276276
override func tearDown() async throws {
277-
self.dbs.shutdown()
277+
await self.dbs.shutdownAsync()
278278
try await super.tearDown()
279279
}
280280
}

Tests/FluentPostgresDriverTests/FluentPostgresTransactionControlTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class FluentPostgresTransactionControlTests: XCTestCase {
5656

5757
override func tearDown() async throws {
5858
try await CreateTodo().revert(on: self.db)
59-
self.dbs.shutdown()
59+
await self.dbs.shutdownAsync()
6060
try await super.tearDown()
6161
}
6262

0 commit comments

Comments
 (0)