Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
linux-integration-sqlite:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.0-noble
container: swift:6.1-noble
steps:
- name: Check out package
uses: actions/checkout@v4
Expand All @@ -58,7 +58,7 @@ jobs:
linux-integration-mysql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.0-noble
container: swift:6.1-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 +77,7 @@ jobs:
linux-integration-psql:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.0-noble
container: swift:6.1-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 +96,7 @@ jobs:
linux-integration-mongo:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:6.0-noble
container: swift:6.1-noble
services:
mongo-a: { image: 'mongo:6' }
mongo-b: { image: 'mongo:6' }
Expand Down
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand All @@ -19,7 +19,6 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.3"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.32.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.20.0"),
],
targets: [
.target(
Expand All @@ -30,7 +29,6 @@ let package = Package(
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "SQLKit", package: "sql-kit"),
],
swiftSettings: swiftSettings
Expand Down Expand Up @@ -78,5 +76,6 @@ var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent-kit/assets/1130717/1da9ba22-253a-43ba-ac03-5cecf0075c30">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent-kit/assets/1130717/89800da9-2651-4fff-900a-be8f691bedb9">
<img src="https://github.com/vapor/fluent-kit/assets/1130717/89800da9-2651-4fff-900a-be8f691bedb9" height="96" alt="FluentKit">
</picture>
<img src="https://design.vapor.codes/images/vapor-fluentkit.svg" height="96" alt="FluentKit">
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<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/swift59up.svg" alt="Swift 5.9+"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
</p>

<br>
Expand Down
14 changes: 8 additions & 6 deletions Sources/FluentBenchmark/SolarSystem/GalacticJurisdiction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ public struct GalacticJurisdictionSeed: Migration {
("Messier 82", "None", 0),
("Messier 82", "Military", 1),
]
.sequencedFlatMapEach(on: database.eventLoop) { galaxyName, jurisdictionName, rank in
GalacticJurisdiction.init(id: try! .init(
galaxy: galaxies.first(where: { $0.name == galaxyName })!,
jurisdiction: jurisdictions.first(where: { $0.title == jurisdictionName })!,
rank: rank
)).create(on: database)
.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)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/SolarSystem/Governor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public struct GovernorSeed: Migration {
case "Earth":
governor = .init(name: "Jane Doe")
default:
return database.eventLoop.future(())
return database.eventLoop.makeSucceededVoidFuture()
}
return planet.$governor.create(governor!, on: database)
}, on: database.eventLoop)
Expand Down
5 changes: 2 additions & 3 deletions Sources/FluentBenchmark/SolarSystem/SolarSystem.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AsyncKit
import FluentKit
import NIOCore

Expand Down Expand Up @@ -36,7 +35,7 @@ public struct SolarSystem: Migration {
all = migrations
}

return all.sequencedFlatMapEach(on: database.eventLoop) { $0.prepare(on: database) }
return all.reduce(database.eventLoop.makeSucceededVoidFuture()) { f, m in f.flatMap { m.prepare(on: database) } }
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
Expand All @@ -47,6 +46,6 @@ public struct SolarSystem: Migration {
all = migrations
}

return all.reversed().sequencedFlatMapEach(on: database.eventLoop) { $0.revert(on: database) }
return all.reversed().reduce(database.eventLoop.makeSucceededVoidFuture()) { f, m in f.flatMap { m.revert(on: database) } }
}
}
4 changes: 2 additions & 2 deletions Sources/FluentBenchmark/Tests/CompositeIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ public struct CompositeIDModelSeed: Migration {
public init() {}

public func prepare(on database: any Database) -> EventLoopFuture<Void> {
[
EventLoopFuture.andAllSucceed([
CompositeIDModel(name: "A", dimensions: 1, additionalInfo: nil),
CompositeIDModel(name: "A", dimensions: 2, additionalInfo: nil),
CompositeIDModel(name: "B", dimensions: 1, additionalInfo: nil),
].map { $0.create(on: database) }.flatten(on: database.eventLoop)
].map { $0.create(on: database) }, on: database.eventLoop)
}

public func revert(on database: any Database) -> EventLoopFuture<Void> {
Expand Down
9 changes: 5 additions & 4 deletions Sources/FluentBenchmark/Tests/CompositeRelationTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
import SQLKit
import FluentKit
import FluentSQL
import SQLKit
import XCTest

extension FluentBenchmarker {
public func testCompositeRelations() throws {
Expand Down Expand Up @@ -215,11 +216,11 @@ final class CompositeIDParentModel: Model, @unchecked Sendable {

struct ModelSeed: Migration {
func prepare(on database: any Database) -> EventLoopFuture<Void> {
[
EventLoopFuture.andAllSucceed([
CompositeIDParentModel(name: "A", dimensions: 1),
CompositeIDParentModel(name: "B", dimensions: 1),
CompositeIDParentModel(name: "C", dimensions: 1),
].map { $0.create(on: database) }.flatten(on: database.eventLoop)
].map { $0.create(on: database) }, on: database.eventLoop)
}

func revert(on database: any Database) -> EventLoopFuture<Void> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/Tests/FilterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private struct FooEnumMigration: Migration {
.case("bar")
.case("baz")
.create()
.transform(to: ())
.map { _ in }
}

func revert(on database: any Database) -> EventLoopFuture<Void> {
Expand Down
3 changes: 2 additions & 1 deletion Sources/FluentBenchmark/Tests/ModelTests.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import FluentKit
import FluentSQL
import Foundation
import NIOCore
import XCTest
import SQLKit
import XCTest

extension FluentBenchmarker {
public func testModel() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ private struct ExpeditionPeopleSeed: Migration {
func prepare(on database: any Database) -> EventLoopFuture<Void> {
if let sqlDatabase = database as? any SQLDatabase {
return
sqlDatabase.select().column("id").from(Expedition.schema).all().flatMapEachThrowing { try $0.decode(column: "id", as: UUID.self) }
.and(sqlDatabase.select().column("id").from(Person.schema).all().flatMapEachThrowing { try $0.decode(column: "id", as: UUID.self) })
sqlDatabase.select().column("id").from(Expedition.schema).all().flatMapThrowing { try $0.map { try $0.decode(column: "id", as: UUID.self) } }
.and(sqlDatabase.select().column("id").from(Person.schema).all().flatMapThrowing { try $0.map { try $0.decode(column: "id", as: UUID.self) } })
.flatMap { expeditions, people in
struct DTO: Codable { let id: UUID, expedition_id: UUID, person_id: UUID }
var officers: [DTO] = [], scientists: [DTO] = [], doctors: [DTO] = []
Expand All @@ -117,7 +117,7 @@ private struct ExpeditionPeopleSeed: Migration {
scientists.append(contentsOf: people.pickRandomly(5).map { DTO(id: UUID(), expedition_id: expedition, person_id: $0) })
doctors.append(contentsOf: people.pickRandomly(3).map { DTO(id: UUID(), expedition_id: expedition, person_id: $0) })
}
return .andAllSucceed([
return EventLoopFuture.andAllSucceed([
try! sqlDatabase.insert(into: ExpeditionOfficer.schema).models(officers).run(),
try! sqlDatabase.insert(into: ExpeditionScientist.schema).models(scientists).run(),
try! sqlDatabase.insert(into: ExpeditionDoctor.schema).models(doctors).run(),
Expand Down
3 changes: 2 additions & 1 deletion Sources/FluentBenchmark/Tests/SQLTests.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import FluentKit
import FluentSQL
import Foundation
import NIOCore
import NIOPosix
import XCTest
import SQLKit
import SQLKitBenchmark
import XCTest

extension FluentBenchmarker {
public func testSQL() throws {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentBenchmark/Tests/SchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct DeleteTableMigration: Migration {
let name: String

func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.eventLoop.future()
database.eventLoop.makeSucceededVoidFuture()
}

func revert(on database: any Database) -> EventLoopFuture<Void> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/fluentkit/images/vapor-fluentkit-logo.svg" }
"icons": { "technology": "/fluentkit/images/FluentKit/vapor-fluentkit-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentKit/Migration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Migration {
}

internal var defaultName: String {
#if compiler(<6.1)
#if compiler(<6.2)
/// `String.init(reflecting:)` creates a `Mirror` unconditionally, but
/// when the parameter is a metatype (such as is the case here), that
/// mirror is never actually used for anything. Unfortunately, just
Expand Down
29 changes: 16 additions & 13 deletions Sources/FluentKit/Migration/Migrator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import AsyncKit
import Logging
import NIOConcurrencyHelpers
import NIOCore

public struct Migrator: Sendable {
Expand Down Expand Up @@ -41,27 +41,27 @@ public struct Migrator: Sendable {
// MARK: Setup

public func setupIfNeeded() -> EventLoopFuture<Void> {
self.migrators() { $0.setupIfNeeded() }.transform(to: ())
self.migrators() { $0.setupIfNeeded() }.map { _ in }
}

// MARK: Prepare

public func prepareBatch() -> EventLoopFuture<Void> {
self.migrators() { $0.prepareBatch() }.transform(to: ())
self.migrators() { $0.prepareBatch() }.map { _ in }
}

// MARK: Revert

public func revertLastBatch() -> EventLoopFuture<Void> {
self.migrators() { $0.revertLastBatch() }.transform(to: ())
self.migrators() { $0.revertLastBatch() }.map { _ in }
}

public func revertBatch(number: Int) -> EventLoopFuture<Void> {
self.migrators() { $0.revertBatch(number: number) }.transform(to: ())
self.migrators() { $0.revertBatch(number: number) }.map { _ in }
}

public func revertAllBatches() -> EventLoopFuture<Void> {
self.migrators() { $0.revertAllBatches() }.transform(to: ())
self.migrators() { $0.revertAllBatches() }.map { _ in }
}

// MARK: Preview
Expand Down Expand Up @@ -99,13 +99,12 @@ public struct Migrator: Sendable {
}
}

private func migrators<Result>(
private func migrators<Result: Sendable>(
_ handler: (DatabaseMigrator) -> EventLoopFuture<Result>
) -> EventLoopFuture<[Result]> {
self.migrations.storage.withLockedValue { $0 }.map {
EventLoopFuture.whenAllSucceed(self.migrations.storage.withLockedValue { $0 }.map {
handler(.init(id: $0, database: self.databaseFactory($0), migrations: $1, migrationLogLevel: self.migrationLogLevel))
}
.flatten(on: self.eventLoop)
}, on: self.eventLoop)
}
}

Expand Down Expand Up @@ -150,7 +149,11 @@ private final class DatabaseMigrator: Sendable {

func prepareBatch() -> EventLoopFuture<Void> {
self.lastBatchNumber().flatMap { batch in
self.unpreparedMigrations().sequencedFlatMapEach { self.prepare($0, batch: batch + 1) }
self.unpreparedMigrations().flatMapWithEventLoop {
$0.reduce($1.makeSucceededVoidFuture()) { future, migration in
future.flatMap { self.prepare(migration, batch: batch + 1) }
}
}
}
}

Expand All @@ -161,11 +164,11 @@ private final class DatabaseMigrator: Sendable {
}

func revertBatch(number: Int) -> EventLoopFuture<Void> {
self.preparedMigrations(batch: number).sequencedFlatMapEach { self.revert($0) }
self.preparedMigrations(batch: number).flatMapWithEventLoop { $0.reduce($1.makeSucceededVoidFuture()) { f, m in f.flatMap { self.revert(m) } } }
}

func revertAllBatches() -> EventLoopFuture<Void> {
self.preparedMigrations().sequencedFlatMapEach { self.revert($0) }
self.preparedMigrations().flatMapWithEventLoop { $0.reduce($1.makeSucceededVoidFuture()) { f, m in f.flatMap { self.revert(m) } } }
}

// MARK: Preview
Expand Down
Loading