Skip to content

Commit

Permalink
Fix up FluentKit tests after SQLKit update (#599)
Browse files Browse the repository at this point in the history
* Fix up FluentKit tests after SQLKit update
* Attempt to fix weird package name issues
* Bump minimum Swift version
* Make FluentKit compliant with ExistentialAny
* Add 5.9 manifest to enforce ExistentialAny
* CI update
  • Loading branch information
gwynne authored Apr 15, 2024
1 parent 5f0938a commit 81db32f
Show file tree
Hide file tree
Showing 112 changed files with 871 additions and 794 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ jobs:
linux-integration:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.8-jammy
container: swift:5.10-jammy
services:
mysql-a:
image: mysql:8.0
image: mysql:8
env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database }
mysql-b:
image: mysql:8.0
image: mysql:8
env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database }
psql-a:
image: postgres:15
image: postgres:16
env: {
POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database,
POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256
}
psql-b:
image: postgres:15
image: postgres:16
env: {
POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database,
POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256
Expand All @@ -76,11 +76,11 @@ jobs:
- { dependent: 'fluent-mongo-driver', ref: 'main' }
steps:
- name: Check out package
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: fluent-kit
- name: Check out dependent
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: vapor/${{ matrix.dependent }}
path: ${{ matrix.dependent }}
Expand All @@ -92,10 +92,7 @@ jobs:
swift package --package-path ${DEPENDENT} edit fluent-kit --path fluent-kit
swift test --package-path ${DEPENDENT}
# also serves as code coverage baseline update
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
with_coverage: true
with_tsan: true
coverage_ignores: '/Tests/|/Sources/FluentBenchmark/'
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription

let package = Package(
Expand All @@ -23,6 +23,7 @@ let package = Package(
],
targets: [
.target(name: "FluentKit", dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
.product(name: "AsyncKit", package: "async-kit"),
Expand Down
74 changes: 74 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "fluent-kit",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
],
products: [
.library(name: "FluentKit", targets: ["FluentKit"]),
.library(name: "FluentBenchmark", targets: ["FluentBenchmark"]),
.library(name: "FluentSQL", targets: ["FluentSQL"]),
.library(name: "XCTFluent", targets: ["XCTFluent"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.55.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.2"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.17.0"),
],
targets: [
.target(
name: "FluentKit",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "SQLKit", package: "sql-kit"),
],
swiftSettings: swiftSettings
),
.target(
name: "FluentBenchmark",
dependencies: [
.target(name: "FluentKit"),
.target(name: "FluentSQL"),
],
swiftSettings: swiftSettings
),
.target(
name: "FluentSQL",
dependencies: [
.target(name: "FluentKit"),
.product(name: "SQLKit", package: "sql-kit"),
],
swiftSettings: swiftSettings
),
.target(
name: "XCTFluent",
dependencies: [
.target(name: "FluentKit"),
.product(name: "NIOEmbedded", package: "swift-nio"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "FluentKitTests",
dependencies: [
.target(name: "FluentBenchmark"),
.target(name: "FluentSQL"),
.target(name: "XCTFluent"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
] }
6 changes: 3 additions & 3 deletions Sources/FluentBenchmark/FluentBenchmarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public final class FluentBenchmarker {

internal func runTest(
_ name: String,
_ migrations: [Migration],
_ migrations: [any Migration],
_ test: () throws -> ()
) throws {
try self.runTest(name, migrations, { _ in try test() })
}

internal func runTest(
_ name: String,
_ migrations: [Migration],
_ migrations: [any Migration],
_ test: (any Database) throws -> ()
) throws {
// This re-initialization is required to make the middleware tests work thanks to ridiculous design flaws
Expand All @@ -75,7 +75,7 @@ public final class FluentBenchmarker {

internal func runTest(
_ name: String,
_ migrations: [Migration],
_ migrations: [any Migration],
on database: any Database,
_ test: (any Database) throws -> ()
) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class GalacticJurisdiction: Model {
public struct GalacticJurisdictionMigration: Migration {
public init() {}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(GalacticJurisdiction.schema)
.field("galaxy_id", .uuid, .required, .references(Galaxy.schema, .id, onDelete: .cascade, onUpdate: .cascade))
.field("jurisdiction_id", .uuid, .required, .references(Jurisdiction.schema, .id, onDelete: .cascade, onUpdate: .cascade))
Expand All @@ -60,7 +60,7 @@ public struct GalacticJurisdictionMigration: Migration {
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema(GalacticJurisdiction.schema)
.delete()
}
Expand All @@ -69,7 +69,7 @@ public struct GalacticJurisdictionMigration: Migration {
public struct GalacticJurisdictionSeed: Migration {
public init() {}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.eventLoop.flatSubmit {
Galaxy.query(on: database).all().and(
Jurisdiction.query(on: database).all())
Expand All @@ -94,7 +94,7 @@ public struct GalacticJurisdictionSeed: Migration {
}
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
GalacticJurisdiction.query(on: database).delete()
}
}
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Galaxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ public final class Galaxy: Model {
public struct GalaxyMigration: Migration {
public init() {}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("galaxies")
.field("id", .uuid, .identifier(auto: false))
.field("name", .string, .required)
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema("galaxies").delete()
}
}

public struct GalaxySeed: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
.andAllSucceed([
"Andromeda",
"Milky Way",
Expand All @@ -56,7 +56,7 @@ public struct GalaxySeed: Migration {
}, on: database.eventLoop)
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
Galaxy.query(on: database).delete()
}
}
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Governor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class Governor: Model {
}

public struct GovernorMigration: Migration {
public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Governor.schema)
.field(.id, .uuid, .identifier(auto: false), .required)
.field("name", .string, .required)
Expand All @@ -39,15 +39,15 @@ public struct GovernorMigration: Migration {
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Governor.schema).delete()
}
}

public struct GovernorSeed: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
Planet.query(on: database).all().flatMap { planets in
.andAllSucceed(planets.map { planet in
let governor: Governor?
Expand All @@ -64,7 +64,7 @@ public struct GovernorSeed: Migration {
}
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
Governor.query(on: database).delete()
}
}
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Jurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public final class Jurisdiction: Model {
public struct JurisdictionMigration: Migration {
public init() {}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Jurisdiction.schema)
.field(.id, .uuid, .identifier(auto: false), .required)
.field("title", .string, .required)
.unique(on: "title")
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema(Jurisdiction.schema)
.delete()
}
Expand All @@ -43,7 +43,7 @@ public struct JurisdictionMigration: Migration {
public struct JurisdictionSeed: Migration {
public init() {}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
[
"Old",
"Corporate",
Expand All @@ -55,7 +55,7 @@ public struct JurisdictionSeed: Migration {
.create(on: database)
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
Jurisdiction.query(on: database)
.delete()
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Moon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class Moon: Model {
public struct MoonMigration: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("moons")
.field("id", .uuid, .identifier(auto: false))
.field("name", .string, .required)
Expand All @@ -48,15 +48,15 @@ public struct MoonMigration: Migration {
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema("moons").delete()
}
}

public final class MoonSeed: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
Planet.query(on: database).all().flatMap { planets in
.andAllSucceed(planets.map { planet in
let moons: [Moon]
Expand Down Expand Up @@ -92,7 +92,7 @@ public final class MoonSeed: Migration {
}
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
Moon.query(on: database).delete()
}
}
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Planet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class Planet: Model {
}

public struct PlanetMigration: Migration {
public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("planets")
.field("id", .uuid, .identifier(auto: false))
.field("name", .string, .required)
Expand All @@ -55,15 +55,15 @@ public struct PlanetMigration: Migration {
.create()
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
database.schema("planets").delete()
}
}

public struct PlanetSeed: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
Star.query(on: database).all().flatMap { stars in
.andAllSucceed(stars.map { star in
let planets: [Planet]
Expand Down Expand Up @@ -91,7 +91,7 @@ public struct PlanetSeed: Migration {
}
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
Planet.query(on: database).delete(force: true)
}
}
Loading

0 comments on commit 81db32f

Please sign in to comment.