Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
branches:
- main

permissions:
contents: read
id-token: write

jobs:
build-and-deploy:
uses: vapor/api-docs/.github/workflows/build-and-deploy-docs-workflow.yml@main
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

env:
LOG_LEVEL: info
SWIFT_DETERMINISTIC_HASHING: 1
POSTGRES_HOSTNAME: 'psql-a'
POSTGRES_HOSTNAME_A: 'psql-a'
POSTGRES_HOSTNAME_B: 'psql-b'
Expand Down Expand Up @@ -37,12 +36,15 @@ env:
MONGO_HOSTNAME_A: 'mongo-a'
MONGO_HOSTNAME_B: 'mongo-b'

permissions:
contents: read

jobs:

linux-integration-sqlite:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.1-noble
container: swift:6.2-noble
steps:
- name: Check out package
uses: actions/checkout@v4
Expand All @@ -58,7 +60,7 @@ jobs:
linux-integration-mysql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.1-noble
container: swift:6.2-noble
services:
mysql-a: { image: 'mysql:9', env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } }
mysql-b: { image: 'mysql:9', env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } }
Expand All @@ -77,7 +79,7 @@ jobs:
linux-integration-psql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.1-noble
container: swift:6.2-noble
services:
psql-a: { image: 'postgres:17', 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:17', 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 @@ -96,7 +98,7 @@ jobs:
linux-integration-mongo:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.1-noble
container: swift:6.2-noble
services:
mongo-a: { image: 'mongo:6' }
mongo-b: { image: 'mongo:6' }
Expand All @@ -117,3 +119,4 @@ jobs:
secrets: inherit
with:
with_android: true
with_linting: true
20 changes: 11 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
import PackageDescription

let package = Package(
Expand Down Expand Up @@ -71,11 +71,13 @@ let package = Package(
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
var swiftSettings: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny"),
// .enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InferIsolatedConformances"),
// .enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/fluent-kit"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
<a href="https://codecov.io/github/vapor/fluent-kit"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-kit?style=plastic&logo=codecov&label=codecov" alt="Code Coverage"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift60up.svg" alt="Swift 6.0+"></a>
</p>

<br>
Expand Down
20 changes: 10 additions & 10 deletions Sources/FluentBenchmark/FluentBenchmarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public final class FluentBenchmarker {

public init(databases: Databases) {
precondition(databases.ids().count >= 2, "FluentBenchmarker Databases instance must have 2 or more registered databases")

self.databases = databases
self.database = self.databases.database(
logger: .init(label: "codes.vapor.fluent.benchmarker"),
Expand Down Expand Up @@ -54,17 +54,17 @@ public final class FluentBenchmarker {
// MARK: Utilities

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

func runTest(
_ name: String,
_ migrations: [any Migration],
_ test: (any Database) throws -> ()
_ test: (any Database) throws -> Void
) throws {
// This re-initialization is required to make the middleware tests work thanks to ridiculous design flaws
self.database = self.databases.database(
Expand All @@ -73,12 +73,12 @@ public final class FluentBenchmarker {
)!
try self.runTest(name, migrations, on: self.database, test)
}

func runTest(
_ name: String,
_ migrations: [any Migration],
on database: any Database,
_ test: (any Database) throws -> ()
_ test: (any Database) throws -> Void
) throws {
database.logger.notice("Running \(name)...")

Expand All @@ -91,7 +91,7 @@ public final class FluentBenchmarker {
database.logger.error("\(name): Error: \(String(reflecting: error))")
throw error
}

let result = Result { try test(database) }

// Revert migrations
Expand All @@ -106,7 +106,7 @@ public final class FluentBenchmarker {
throw error
}
}

if case .failure(let error) = result {
database.logger.error("\(name): Error: \(String(reflecting: error))")
throw error
Expand Down
44 changes: 23 additions & 21 deletions Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ import NIOCore

public final class GalacticJurisdiction: Model, @unchecked Sendable {
public static let schema = "galaxy_jurisdictions"

public final class IDValue: Fields, Hashable, @unchecked Sendable {
@Parent(key: "galaxy_id")
public var galaxy: Galaxy

@Parent(key: "jurisdiction_id")
public var jurisdiction: Jurisdiction

@Field(key: "rank")
public var rank: Int

public init() {}

public convenience init(galaxy: Galaxy, jurisdiction: Jurisdiction, rank: Int) throws {
try self.init(galaxyId: galaxy.requireID(), jurisdictionId: jurisdiction.requireID(), rank: rank)
}

public init(galaxyId: Galaxy.IDValue, jurisdictionId: Jurisdiction.IDValue, rank: Int) {
self.$galaxy.id = galaxyId
self.$jurisdiction.id = jurisdictionId
self.rank = rank
}

public static func == (lhs: IDValue, rhs: IDValue) -> Bool {
lhs.$galaxy.id == rhs.$galaxy.id && lhs.$jurisdiction.id == rhs.$jurisdiction.id && lhs.rank == rhs.rank
}

public func hash(into hasher: inout Hasher) {
hasher.combine(self.$galaxy.id)
hasher.combine(self.$jurisdiction.id)
hasher.combine(self.rank)
}
}

@CompositeID()
public var id: IDValue?

public init() {}

public init(id: IDValue) {
self.id = id
}
}

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

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))
Expand All @@ -59,7 +59,7 @@ public struct GalacticJurisdictionMigration: Migration {
.compositeIdentifier(over: "galaxy_id", "jurisdiction_id", "rank")
.create()
}

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

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

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.eventLoop.flatSubmit {
Galaxy.query(on: database).all().and(
Jurisdiction.query(on: database).all())
Jurisdiction.query(on: database).all())
}.flatMap { galaxies, jurisdictions in
[
("Milky Way", "Old", 0),
Expand All @@ -86,16 +86,18 @@ public struct GalacticJurisdictionSeed: Migration {
]
.reduce(database.eventLoop.makeSucceededVoidFuture()) { future, data in
future.flatMap {
GalacticJurisdiction.init(id: try! .init(
galaxy: galaxies.first(where: { $0.name == data.0 })!,
jurisdiction: jurisdictions.first(where: { $0.title == data.1 })!,
rank: data.2
)).create(on: database)
GalacticJurisdiction.init(
id: try! .init(
galaxy: galaxies.first(where: { $0.name == data.0 })!,
jurisdiction: jurisdictions.first(where: { $0.title == data.1 })!,
rank: data.2
)
).create(on: database)
}
}
}
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
GalacticJurisdiction.query(on: database).delete()
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/FluentBenchmark/SolarSystem/Galaxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XCTest

public final class Galaxy: Model, @unchecked Sendable {
public static let schema = "galaxies"

@ID
public var id: UUID?

Expand All @@ -14,7 +14,7 @@ public final class Galaxy: Model, @unchecked Sendable {

@Children(for: \.$galaxy)
public var stars: [Star]

@Siblings(through: GalacticJurisdiction.self, from: \.$id.$galaxy, to: \.$id.$jurisdiction)
public var jurisdictions: [Jurisdiction]

Expand Down Expand Up @@ -49,7 +49,7 @@ public struct GalaxySeed: AsyncMigration {
"Andromeda",
"Milky Way",
"Pinwheel Galaxy",
"Messier 82"
"Messier 82",
]
.map { Galaxy(name: $0) }
.create(on: database)
Expand Down
29 changes: 15 additions & 14 deletions Sources/FluentBenchmark/SolarSystem/Governor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class Governor: Model, @unchecked Sendable {
@Parent(key: "planet_id")
public var planet: Planet

public init() { }
public init() {}

public init(id: IDValue? = nil, name: String) {
self.id = id
Expand Down Expand Up @@ -45,22 +45,23 @@ public struct GovernorMigration: Migration {
}

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

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?
switch planet.name {
case "Mars":
governor = .init(name: "John Doe")
case "Earth":
governor = .init(name: "Jane Doe")
default:
return database.eventLoop.makeSucceededVoidFuture()
}
return planet.$governor.create(governor!, on: database)
}, on: database.eventLoop)
.andAllSucceed(
planets.map { planet in
let governor: Governor?
switch planet.name {
case "Mars":
governor = .init(name: "John Doe")
case "Earth":
governor = .init(name: "Jane Doe")
default:
return database.eventLoop.makeSucceededVoidFuture()
}
return planet.$governor.create(governor!, on: database)
}, on: database.eventLoop)
}
}

Expand Down
Loading
Loading