Skip to content

Commit

Permalink
Make FluentKit compliant with ExistentialAny
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne committed Apr 15, 2024
1 parent ccc44a4 commit 81ea23d
Show file tree
Hide file tree
Showing 108 changed files with 757 additions and 752 deletions.
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)
}
}
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/PlanetTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class PlanetTag: Model {
public struct PlanetTagMigration: Migration {
public init() { }

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema(PlanetTag.schema)
.id()
.field("planet_id", .uuid, .required)
Expand All @@ -42,15 +42,15 @@ public struct PlanetTagMigration: Migration {
.create()
}

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

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

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
let planets = Planet.query(on: database).all()
let tags = Tag.query(on: database).all()
return planets.and(tags).flatMap { (planets, tags) in
Expand All @@ -75,7 +75,7 @@ public struct PlanetTagSeed: Migration {
}
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
public func revert(on database: any Database) -> EventLoopFuture<Void> {
PlanetTag.query(on: database).delete()
}
}
12 changes: 6 additions & 6 deletions Sources/FluentBenchmark/SolarSystem/SolarSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AsyncKit
import FluentKit
import NIOCore

private let migrations: [Migration] = [
private let migrations: [any Migration] = [
GalaxyMigration(),
StarMigration(),
PlanetMigration(),
Expand All @@ -12,7 +12,7 @@ private let migrations: [Migration] = [
PlanetTagMigration(),
]

private let seeds: [Migration] = [
private let seeds: [any Migration] = [
GalaxySeed(),
StarSeed(),
PlanetSeed(),
Expand All @@ -28,8 +28,8 @@ public struct SolarSystem: Migration {
self.seed = seed
}

public func prepare(on database: Database) -> EventLoopFuture<Void> {
let all: [Migration]
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
let all: [any Migration]
if self.seed {
all = migrations + seeds
} else {
Expand All @@ -39,8 +39,8 @@ public struct SolarSystem: Migration {
return all.sequencedFlatMapEach(on: database.eventLoop) { $0.prepare(on: database) }
}

public func revert(on database: Database) -> EventLoopFuture<Void> {
let all: [Migration]
public func revert(on database: any Database) -> EventLoopFuture<Void> {
let all: [any Migration]
if self.seed {
all = migrations + seeds
} else {
Expand Down
8 changes: 4 additions & 4 deletions Sources/FluentBenchmark/SolarSystem/Star.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class Star: Model {
}

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

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

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

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
Galaxy.query(on: database).all().flatMap { galaxies in
.andAllSucceed(galaxies.map { galaxy in
let stars: [Star]
Expand All @@ -64,7 +64,7 @@ public final class StarSeed: Migration {
}
}

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

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
database.schema("tags")
.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("tags").delete()
}
}

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

public func prepare(on database: Database) -> EventLoopFuture<Void> {
public func prepare(on database: any Database) -> EventLoopFuture<Void> {
.andAllSucceed([
"Small Rocky", "Gas Giant", "Inhabited"
].map {
Expand All @@ -50,7 +50,7 @@ public final class TagSeed: Migration {
}, on: database.eventLoop)
}

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

0 comments on commit 81ea23d

Please sign in to comment.