diff --git a/Sources/App/Migrations/001/CreatePackage.swift b/Sources/App/Migrations/001/CreatePackage.swift index 92a8bb031..e0e9aa7a8 100644 --- a/Sources/App/Migrations/001/CreatePackage.swift +++ b/Sources/App/Migrations/001/CreatePackage.swift @@ -14,9 +14,9 @@ import Fluent -struct CreatePackage: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("packages") +struct CreatePackage: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("packages") // managed fields .id() .field("created_at", .datetime) @@ -31,7 +31,7 @@ struct CreatePackage: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("packages").delete() + func revert(on database: Database) async throws { + try await database.schema("packages").delete() } } diff --git a/Sources/App/Migrations/001/CreateProduct.swift b/Sources/App/Migrations/001/CreateProduct.swift index 8af3f6058..3015aaed8 100644 --- a/Sources/App/Migrations/001/CreateProduct.swift +++ b/Sources/App/Migrations/001/CreateProduct.swift @@ -14,9 +14,9 @@ import Fluent -struct CreateProduct: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("products") +struct CreateProduct: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("products") // managed fields .id() .field("created_at", .datetime) @@ -33,7 +33,7 @@ struct CreateProduct: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("products").delete() + func revert(on database: Database) async throws { + try await database.schema("products").delete() } } diff --git a/Sources/App/Migrations/001/CreateRecentPackages.swift b/Sources/App/Migrations/001/CreateRecentPackages.swift index c8ab4745f..61f57ec1c 100644 --- a/Sources/App/Migrations/001/CreateRecentPackages.swift +++ b/Sources/App/Migrations/001/CreateRecentPackages.swift @@ -16,12 +16,12 @@ import Fluent import SQLKit -struct CreateRecentPackages: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateRecentPackages: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( """ -- v0 CREATE MATERIALIZED VIEW recent_packages AS @@ -39,10 +39,10 @@ struct CreateRecentPackages: Migration { ).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("DROP MATERIALIZED VIEW recent_packages").run() + try await db.raw("DROP MATERIALIZED VIEW recent_packages").run() } } diff --git a/Sources/App/Migrations/001/CreateRecentReleases.swift b/Sources/App/Migrations/001/CreateRecentReleases.swift index ad65a39fc..bf208ce89 100644 --- a/Sources/App/Migrations/001/CreateRecentReleases.swift +++ b/Sources/App/Migrations/001/CreateRecentReleases.swift @@ -16,12 +16,12 @@ import Fluent import SQLKit -struct CreateRecentReleases: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateRecentReleases: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( """ -- v0 CREATE MATERIALIZED VIEW recent_releases AS @@ -40,10 +40,10 @@ struct CreateRecentReleases: Migration { ).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("DROP MATERIALIZED VIEW recent_releases").run() + try await db.raw("DROP MATERIALIZED VIEW recent_releases").run() } } diff --git a/Sources/App/Migrations/001/CreateRepository.swift b/Sources/App/Migrations/001/CreateRepository.swift index d7b5f7e42..fbcb2c0ac 100644 --- a/Sources/App/Migrations/001/CreateRepository.swift +++ b/Sources/App/Migrations/001/CreateRepository.swift @@ -14,9 +14,9 @@ import Fluent -struct CreateRepository: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("repositories") +struct CreateRepository: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") // managed fields .id() .field("created_at", .datetime) @@ -48,7 +48,7 @@ struct CreateRepository: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("repositories").delete() + func revert(on database: Database) async throws { + try await database.schema("repositories").delete() } } diff --git a/Sources/App/Migrations/001/CreateSearch.swift b/Sources/App/Migrations/001/CreateSearch.swift index 0b4be37fc..43d385b42 100644 --- a/Sources/App/Migrations/001/CreateSearch.swift +++ b/Sources/App/Migrations/001/CreateSearch.swift @@ -16,12 +16,12 @@ import Fluent import SQLKit -struct CreateSearch: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateSearch: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( """ -- v1 CREATE MATERIALIZED VIEW search AS @@ -40,10 +40,10 @@ struct CreateSearch: Migration { ).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("DROP MATERIALIZED VIEW search").run() + try await db.raw("DROP MATERIALIZED VIEW search").run() } } diff --git a/Sources/App/Migrations/001/CreateVersion.swift b/Sources/App/Migrations/001/CreateVersion.swift index a7d3220d2..16625c465 100644 --- a/Sources/App/Migrations/001/CreateVersion.swift +++ b/Sources/App/Migrations/001/CreateVersion.swift @@ -14,9 +14,9 @@ import Fluent -struct CreateVersion: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("versions") +struct CreateVersion: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") // managed fields .id() .field("created_at", .datetime) @@ -37,7 +37,7 @@ struct CreateVersion: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("versions").delete() + func revert(on database: Database) async throws { + try await database.schema("versions").delete() } } diff --git a/Sources/App/Migrations/002/CreateOwnerRepositoryIndex.swift b/Sources/App/Migrations/002/CreateOwnerRepositoryIndex.swift index c847ceca4..116819ca0 100644 --- a/Sources/App/Migrations/002/CreateOwnerRepositoryIndex.swift +++ b/Sources/App/Migrations/002/CreateOwnerRepositoryIndex.swift @@ -16,12 +16,12 @@ import Fluent import SQLKit -struct CreateOwnerRepositoryIndex: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateOwnerRepositoryIndex: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( """ CREATE UNIQUE INDEX idx_repositories_owner_name ON repositories (LOWER(owner), LOWER(name)) @@ -29,10 +29,10 @@ struct CreateOwnerRepositoryIndex: Migration { ).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("DROP INDEX idx_repositories_owner_name").run() + try await db.raw("DROP INDEX idx_repositories_owner_name").run() } } diff --git a/Sources/App/Migrations/002/CreateRepositoriesNameIndex.swift b/Sources/App/Migrations/002/CreateRepositoriesNameIndex.swift index 6858909f8..16c110a5b 100644 --- a/Sources/App/Migrations/002/CreateRepositoriesNameIndex.swift +++ b/Sources/App/Migrations/002/CreateRepositoriesNameIndex.swift @@ -16,25 +16,23 @@ import Fluent import SQLKit -struct CreateRepositoriesNameIndex: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateRepositoriesNameIndex: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } // See https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/176#issuecomment-637710906 // for details about this index - return db.raw("CREATE EXTENSION IF NOT EXISTS pg_trgm").run() - .flatMap { - db.raw("CREATE INDEX idx_repositories_name ON repositories USING gin (name gin_trgm_ops)").run() } + try await db.raw("CREATE EXTENSION IF NOT EXISTS pg_trgm").run() + try await db.raw("CREATE INDEX idx_repositories_name ON repositories USING gin (name gin_trgm_ops)").run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return - db.raw("DROP INDEX idx_repositories_name").run() - .flatMap { db.raw("DROP EXTENSION pg_trgm").run() } + try await db.raw("DROP INDEX idx_repositories_name").run() + try await db.raw("DROP EXTENSION pg_trgm").run() } } diff --git a/Sources/App/Migrations/003/UpdateRecentPackages1.swift b/Sources/App/Migrations/003/UpdateRecentPackages1.swift index 82f3abd6b..d17be358d 100644 --- a/Sources/App/Migrations/003/UpdateRecentPackages1.swift +++ b/Sources/App/Migrations/003/UpdateRecentPackages1.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentPackages1: Migration { +struct UpdateRecentPackages1: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_packages" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -43,11 +43,11 @@ struct UpdateRecentPackages1: Migration { ORDER BY MAX(p.created_at) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -66,7 +66,7 @@ struct UpdateRecentPackages1: Migration { ORDER BY MAX(p.created_at) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/003/UpdateRecentReleases1.swift b/Sources/App/Migrations/003/UpdateRecentReleases1.swift index 3f08a741b..e55a378f7 100644 --- a/Sources/App/Migrations/003/UpdateRecentReleases1.swift +++ b/Sources/App/Migrations/003/UpdateRecentReleases1.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases1: Migration { +struct UpdateRecentReleases1: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -44,11 +44,11 @@ struct UpdateRecentReleases1: Migration { ORDER BY MAX(v.commit_date) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -68,7 +68,7 @@ struct UpdateRecentReleases1: Migration { ORDER BY MAX(commit_date) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/004/UpdatePackageStatusNew.swift b/Sources/App/Migrations/004/UpdatePackageStatusNew.swift index 6ef066fb3..c2f9690b2 100644 --- a/Sources/App/Migrations/004/UpdatePackageStatusNew.swift +++ b/Sources/App/Migrations/004/UpdatePackageStatusNew.swift @@ -16,26 +16,22 @@ import Fluent import SQLKit -struct UpdatePackageStatusNew: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct UpdatePackageStatusNew: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("ALTER TABLE packages ALTER COLUMN status SET DEFAULT 'new'").run() - .flatMap { - db.raw("ALTER TABLE packages ALTER COLUMN status SET NOT NULL").run() - } + try await db.raw("ALTER TABLE packages ALTER COLUMN status SET DEFAULT 'new'").run() + try await db.raw("ALTER TABLE packages ALTER COLUMN status SET NOT NULL").run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("ALTER TABLE packages ALTER COLUMN status DROP NOT NULL").run() - .flatMap { - db.raw("ALTER TABLE packages ALTER COLUMN status DROP DEFAULT").run() - } + try await db.raw("ALTER TABLE packages ALTER COLUMN status DROP NOT NULL").run() + try await db.raw("ALTER TABLE packages ALTER COLUMN status DROP DEFAULT").run() } } diff --git a/Sources/App/Migrations/005/UpdateRecentPackages2.swift b/Sources/App/Migrations/005/UpdateRecentPackages2.swift index 6b97b4d54..ec6f5c327 100644 --- a/Sources/App/Migrations/005/UpdateRecentPackages2.swift +++ b/Sources/App/Migrations/005/UpdateRecentPackages2.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentPackages2: Migration { +struct UpdateRecentPackages2: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_packages" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -44,11 +44,11 @@ struct UpdateRecentPackages2: Migration { ORDER BY MAX(p.created_at) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -72,7 +72,7 @@ struct UpdateRecentPackages2: Migration { ORDER BY MAX(p.created_at) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/005/UpdateRecentReleases2.swift b/Sources/App/Migrations/005/UpdateRecentReleases2.swift index 5be3f571d..3a0693b57 100644 --- a/Sources/App/Migrations/005/UpdateRecentReleases2.swift +++ b/Sources/App/Migrations/005/UpdateRecentReleases2.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases2: Migration { +struct UpdateRecentReleases2: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -53,11 +53,11 @@ struct UpdateRecentReleases2: Migration { ORDER BY released_at DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -82,7 +82,7 @@ struct UpdateRecentReleases2: Migration { ORDER BY MAX(v.commit_date) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/006/UpdateRecentReleases3.swift b/Sources/App/Migrations/006/UpdateRecentReleases3.swift index 023db0d0f..637f38603 100644 --- a/Sources/App/Migrations/006/UpdateRecentReleases3.swift +++ b/Sources/App/Migrations/006/UpdateRecentReleases3.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases3: Migration { +struct UpdateRecentReleases3: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -55,11 +55,11 @@ struct UpdateRecentReleases3: Migration { ORDER BY released_at DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -93,7 +93,7 @@ struct UpdateRecentReleases3: Migration { ORDER BY released_at DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/007/UpdateRecentPackages3.swift b/Sources/App/Migrations/007/UpdateRecentPackages3.swift index 5a15c2c20..f70cbee3b 100644 --- a/Sources/App/Migrations/007/UpdateRecentPackages3.swift +++ b/Sources/App/Migrations/007/UpdateRecentPackages3.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentPackages3: Migration { +struct UpdateRecentPackages3: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_packages" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -46,11 +46,11 @@ struct UpdateRecentPackages3: Migration { order by created_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -75,7 +75,7 @@ struct UpdateRecentPackages3: Migration { ORDER BY MAX(p.created_at) DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/007/UpdateRecentReleases4.swift b/Sources/App/Migrations/007/UpdateRecentReleases4.swift index f22ef3e50..ce8c0c156 100644 --- a/Sources/App/Migrations/007/UpdateRecentReleases4.swift +++ b/Sources/App/Migrations/007/UpdateRecentReleases4.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases4: Migration { +struct UpdateRecentReleases4: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -46,11 +46,11 @@ struct UpdateRecentReleases4: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -86,7 +86,7 @@ struct UpdateRecentReleases4: Migration { ORDER BY released_at DESC LIMIT 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/008/CreateStats.swift b/Sources/App/Migrations/008/CreateStats.swift index dc3d06b6f..b4c2c9b61 100644 --- a/Sources/App/Migrations/008/CreateStats.swift +++ b/Sources/App/Migrations/008/CreateStats.swift @@ -16,12 +16,12 @@ import Fluent import SQLKit -struct CreateStats: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct CreateStats: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( """ -- v0 CREATE MATERIALIZED VIEW stats AS @@ -33,10 +33,10 @@ struct CreateStats: Migration { ).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw("DROP MATERIALIZED VIEW stats").run() + try await db.raw("DROP MATERIALIZED VIEW stats").run() } } diff --git a/Sources/App/Migrations/009/CreateBuild.swift b/Sources/App/Migrations/009/CreateBuild.swift index 75df2883e..2a9ec2564 100644 --- a/Sources/App/Migrations/009/CreateBuild.swift +++ b/Sources/App/Migrations/009/CreateBuild.swift @@ -15,9 +15,9 @@ import Fluent -struct CreateBuild: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("builds") +struct CreateBuild: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") // managed fields .id() .field("created_at", .datetime) @@ -39,7 +39,7 @@ struct CreateBuild: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("builds").delete() + func revert(on database: Database) async throws { + try await database.schema("builds").delete() } } diff --git a/Sources/App/Migrations/010/UpdateBuildNonNull.swift b/Sources/App/Migrations/010/UpdateBuildNonNull.swift index ccc5aece8..445fc4781 100644 --- a/Sources/App/Migrations/010/UpdateBuildNonNull.swift +++ b/Sources/App/Migrations/010/UpdateBuildNonNull.swift @@ -15,9 +15,9 @@ import Fluent -struct UpdateBuildNonNull: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildNonNull: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .deleteField("platform").field("platform", .json, .required) .deleteField("status").field("status", .string, .required) .deleteField("swift_version").field("swift_version", .json, .required) @@ -25,8 +25,8 @@ struct UpdateBuildNonNull: Migration { .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("platform").field("platform", .json) .deleteField("status").field("status", .string) .deleteField("swift_version").field("swift_version", .json) diff --git a/Sources/App/Migrations/011/UpdateBuildAddLogURL.swift b/Sources/App/Migrations/011/UpdateBuildAddLogURL.swift index 61ae2a8a9..1b006d793 100644 --- a/Sources/App/Migrations/011/UpdateBuildAddLogURL.swift +++ b/Sources/App/Migrations/011/UpdateBuildAddLogURL.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateBuildAddLogURL: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildAddLogURL: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .field("log_url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("log_url") .update() } diff --git a/Sources/App/Migrations/012/UpdateBuildPlatform.swift b/Sources/App/Migrations/012/UpdateBuildPlatform.swift index 1b91af84e..7a1eccc04 100644 --- a/Sources/App/Migrations/012/UpdateBuildPlatform.swift +++ b/Sources/App/Migrations/012/UpdateBuildPlatform.swift @@ -15,16 +15,16 @@ import Fluent -struct UpdateBuildPlatform: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildPlatform: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .deleteField("platform").field("platform", .string, .required) .unique(on: "version_id", "platform", "swift_version") .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("platform").field("platform", .json, .required) .unique(on: "version_id", "platform", "swift_version") .update() diff --git a/Sources/App/Migrations/013/UpdateBuildAddBuildCommand.swift b/Sources/App/Migrations/013/UpdateBuildAddBuildCommand.swift index 43bbf7330..50aa5322a 100644 --- a/Sources/App/Migrations/013/UpdateBuildAddBuildCommand.swift +++ b/Sources/App/Migrations/013/UpdateBuildAddBuildCommand.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateBuildAddBuildCommand: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildAddBuildCommand: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .field("build_command", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("build_command") .update() } diff --git a/Sources/App/Migrations/014/UpdateVersionAddLatest.swift b/Sources/App/Migrations/014/UpdateVersionAddLatest.swift index d69310338..c37680673 100644 --- a/Sources/App/Migrations/014/UpdateVersionAddLatest.swift +++ b/Sources/App/Migrations/014/UpdateVersionAddLatest.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateVersionAddLatest: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddLatest: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("latest", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("latest") .update() } diff --git a/Sources/App/Migrations/016/UpdateBuildAddJobUrl.swift b/Sources/App/Migrations/016/UpdateBuildAddJobUrl.swift index 5dad2c94d..d4bfef28f 100644 --- a/Sources/App/Migrations/016/UpdateBuildAddJobUrl.swift +++ b/Sources/App/Migrations/016/UpdateBuildAddJobUrl.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateBuildAddJobUrl: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildAddJobUrl: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .field("job_url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("job_url") .update() } diff --git a/Sources/App/Migrations/017/UpdateBuildRemoveLogs.swift b/Sources/App/Migrations/017/UpdateBuildRemoveLogs.swift index a2dd6488c..6ea8c02f4 100644 --- a/Sources/App/Migrations/017/UpdateBuildRemoveLogs.swift +++ b/Sources/App/Migrations/017/UpdateBuildRemoveLogs.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateBuildRemoveLogs: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildRemoveLogs: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .deleteField("logs") .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .field("logs", .string) .update() } diff --git a/Sources/App/Migrations/018/UpdateRepositoryAddLicenseUrl.swift b/Sources/App/Migrations/018/UpdateRepositoryAddLicenseUrl.swift index a365e652a..5ed7b71b8 100644 --- a/Sources/App/Migrations/018/UpdateRepositoryAddLicenseUrl.swift +++ b/Sources/App/Migrations/018/UpdateRepositoryAddLicenseUrl.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddLicenseUrl: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddLicenseUrl: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("license_url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("license_url") .update() } diff --git a/Sources/App/Migrations/019/UpdateRepositoryAddReadmeUrl.swift b/Sources/App/Migrations/019/UpdateRepositoryAddReadmeUrl.swift index 6745f6eeb..d20e58a30 100644 --- a/Sources/App/Migrations/019/UpdateRepositoryAddReadmeUrl.swift +++ b/Sources/App/Migrations/019/UpdateRepositoryAddReadmeUrl.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddReadmeUrl: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddReadmeUrl: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("readme_url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("readme_url") .update() } diff --git a/Sources/App/Migrations/020/UpdateVersionAddToolsVersion.swift b/Sources/App/Migrations/020/UpdateVersionAddToolsVersion.swift index 7101c497e..c84884f1a 100644 --- a/Sources/App/Migrations/020/UpdateVersionAddToolsVersion.swift +++ b/Sources/App/Migrations/020/UpdateVersionAddToolsVersion.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateVersionAddToolsVersion: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddToolsVersion: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("tools_version", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("tools_version") .update() } diff --git a/Sources/App/Migrations/021/UpdateRecentReleases5.swift b/Sources/App/Migrations/021/UpdateRecentReleases5.swift index 4a27c832f..8d01421b6 100644 --- a/Sources/App/Migrations/021/UpdateRecentReleases5.swift +++ b/Sources/App/Migrations/021/UpdateRecentReleases5.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases5: Migration { +struct UpdateRecentReleases5: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -47,11 +47,11 @@ struct UpdateRecentReleases5: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -78,7 +78,7 @@ struct UpdateRecentReleases5: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/021/UpdateVersionAddUrl.swift b/Sources/App/Migrations/021/UpdateVersionAddUrl.swift index 4c0cb737f..a4081a794 100644 --- a/Sources/App/Migrations/021/UpdateVersionAddUrl.swift +++ b/Sources/App/Migrations/021/UpdateVersionAddUrl.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateVersionAddUrl: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddUrl: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("url") .update() } diff --git a/Sources/App/Migrations/022/UpdateRepositoryAddIsArchived.swift b/Sources/App/Migrations/022/UpdateRepositoryAddIsArchived.swift index ab5d24410..4c6220e43 100644 --- a/Sources/App/Migrations/022/UpdateRepositoryAddIsArchived.swift +++ b/Sources/App/Migrations/022/UpdateRepositoryAddIsArchived.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddIsArchived: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddIsArchived: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("is_archived", .bool) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("is_archived") .update() } diff --git a/Sources/App/Migrations/023/UpdateRepositoryAddReleases.swift b/Sources/App/Migrations/023/UpdateRepositoryAddReleases.swift index fd2db8717..2f55d6807 100644 --- a/Sources/App/Migrations/023/UpdateRepositoryAddReleases.swift +++ b/Sources/App/Migrations/023/UpdateRepositoryAddReleases.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddReleases: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddReleases: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("releases", .array(of: .json), .sql(.default("{}"))) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("releases") .update() } diff --git a/Sources/App/Migrations/023/UpdateVersionAddPublisedAtReleaseNotes.swift b/Sources/App/Migrations/023/UpdateVersionAddPublisedAtReleaseNotes.swift index 14bc19eb7..1da04e4f8 100644 --- a/Sources/App/Migrations/023/UpdateVersionAddPublisedAtReleaseNotes.swift +++ b/Sources/App/Migrations/023/UpdateVersionAddPublisedAtReleaseNotes.swift @@ -15,16 +15,16 @@ import Fluent -struct UpdateVersionAddPublisedAtReleaseNotes: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddPublisedAtReleaseNotes: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("published_at", .datetime) .field("release_notes", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("published_at") .deleteField("release_notes") .update() diff --git a/Sources/App/Migrations/024/CreateTarget.swift b/Sources/App/Migrations/024/CreateTarget.swift index fa616ecc5..1b86ec521 100644 --- a/Sources/App/Migrations/024/CreateTarget.swift +++ b/Sources/App/Migrations/024/CreateTarget.swift @@ -14,9 +14,9 @@ import Fluent -struct CreateTarget: Migration { - func prepare(on database: Database) -> EventLoopFuture { - return database.schema("targets") +struct CreateTarget: AsyncMigration { + func prepare(on database: Database) async throws { + return try await database.schema("targets") // managed fields .id() .field("created_at", .datetime) @@ -32,7 +32,7 @@ struct CreateTarget: Migration { .create() } - func revert(on database: Database) -> EventLoopFuture { - return database.schema("targets").delete() + func revert(on database: Database) async throws { + return try await database.schema("targets").delete() } } diff --git a/Sources/App/Migrations/025/UpdateProductAddTargets.swift b/Sources/App/Migrations/025/UpdateProductAddTargets.swift index fadffae79..9b149b98a 100644 --- a/Sources/App/Migrations/025/UpdateProductAddTargets.swift +++ b/Sources/App/Migrations/025/UpdateProductAddTargets.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateProductAddTargets: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("products") +struct UpdateProductAddTargets: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("products") .field("targets", .array(of: .string), .sql(.default("{}"))) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("products") + func revert(on database: Database) async throws { + try await database.schema("products") .deleteField("targets") .update() } diff --git a/Sources/App/Migrations/026/UpdateRepositoryAddReadmeHtmlUrl.swift b/Sources/App/Migrations/026/UpdateRepositoryAddReadmeHtmlUrl.swift index d9563b3c5..7a9a16d26 100644 --- a/Sources/App/Migrations/026/UpdateRepositoryAddReadmeHtmlUrl.swift +++ b/Sources/App/Migrations/026/UpdateRepositoryAddReadmeHtmlUrl.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddReadmeHtmlUrl: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddReadmeHtmlUrl: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("readme_html_url", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("readme_html_url") .update() } diff --git a/Sources/App/Migrations/027/UpdateRepositoryAddOwnerFields.swift b/Sources/App/Migrations/027/UpdateRepositoryAddOwnerFields.swift index 8054fdc74..eb5895ef1 100644 --- a/Sources/App/Migrations/027/UpdateRepositoryAddOwnerFields.swift +++ b/Sources/App/Migrations/027/UpdateRepositoryAddOwnerFields.swift @@ -15,17 +15,17 @@ import Fluent -struct UpdateRepositoryAddOwnerFields: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddOwnerFields: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("owner_name", .string) .field("owner_avatar_url", .string) .field("is_in_organization", .bool) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("owner_name") .deleteField("owner_avatar_url") .deleteField("is_in_organization") diff --git a/Sources/App/Migrations/028/UpdateProductType.swift b/Sources/App/Migrations/028/UpdateProductType.swift index 722e8fe34..8bd3df072 100644 --- a/Sources/App/Migrations/028/UpdateProductType.swift +++ b/Sources/App/Migrations/028/UpdateProductType.swift @@ -14,16 +14,16 @@ import Fluent -struct UpdateProductType: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("products") +struct UpdateProductType: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("products") .deleteField("type") .field("type", .json) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("products") + func revert(on database: Database) async throws { + try await database.schema("products") .deleteField("type") .field("type", .string, .required) .update() diff --git a/Sources/App/Migrations/029/UpdateRecentReleases6.swift b/Sources/App/Migrations/029/UpdateRecentReleases6.swift index 5bd3acb1d..26763d11c 100644 --- a/Sources/App/Migrations/029/UpdateRecentReleases6.swift +++ b/Sources/App/Migrations/029/UpdateRecentReleases6.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases6: Migration { +struct UpdateRecentReleases6: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -48,11 +48,11 @@ struct UpdateRecentReleases6: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -80,7 +80,7 @@ struct UpdateRecentReleases6: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/029/UpdateVersionAddReleaseNotesHTML.swift b/Sources/App/Migrations/029/UpdateVersionAddReleaseNotesHTML.swift index adf42bc75..472f8297c 100644 --- a/Sources/App/Migrations/029/UpdateVersionAddReleaseNotesHTML.swift +++ b/Sources/App/Migrations/029/UpdateVersionAddReleaseNotesHTML.swift @@ -15,15 +15,15 @@ import Fluent import SQLKit -struct UpdateVersionAddReleaseNotesHTML: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddReleaseNotesHTML: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("release_notes_html", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("release_notes_html") .update() } diff --git a/Sources/App/Migrations/030/UpdateRepositoryAddKeywords.swift b/Sources/App/Migrations/030/UpdateRepositoryAddKeywords.swift index 95d99aa42..bb8de361a 100644 --- a/Sources/App/Migrations/030/UpdateRepositoryAddKeywords.swift +++ b/Sources/App/Migrations/030/UpdateRepositoryAddKeywords.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateRepositoryAddKeywords: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("repositories") +struct UpdateRepositoryAddKeywords: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("repositories") .field("keywords", .array(of: .string), .sql(.default("{}"))) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("repositories") + func revert(on database: Database) async throws { + try await database.schema("repositories") .deleteField("keywords") .update() } diff --git a/Sources/App/Migrations/031/UpdateSearch1.swift b/Sources/App/Migrations/031/UpdateSearch1.swift index 00bf21710..2c74574ff 100644 --- a/Sources/App/Migrations/031/UpdateSearch1.swift +++ b/Sources/App/Migrations/031/UpdateSearch1.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateSearch1: Migration { +struct UpdateSearch1: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW search" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -40,11 +40,11 @@ struct UpdateSearch1: Migration { JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -64,7 +64,7 @@ struct UpdateSearch1: Migration { JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/032/UpdateSearch2.swift b/Sources/App/Migrations/032/UpdateSearch2.swift index fe7a529ac..51bd37caf 100644 --- a/Sources/App/Migrations/032/UpdateSearch2.swift +++ b/Sources/App/Migrations/032/UpdateSearch2.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateSearch2: Migration { +struct UpdateSearch2: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW search" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -43,11 +43,11 @@ struct UpdateSearch2: Migration { JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -68,7 +68,7 @@ struct UpdateSearch2: Migration { JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/033/UpdateVersionAddResolvedDependencies.swift b/Sources/App/Migrations/033/UpdateVersionAddResolvedDependencies.swift index 5fe474bdf..2e37166ef 100644 --- a/Sources/App/Migrations/033/UpdateVersionAddResolvedDependencies.swift +++ b/Sources/App/Migrations/033/UpdateVersionAddResolvedDependencies.swift @@ -14,9 +14,9 @@ import Fluent -struct UpdateVersionAddResolvedDependencies: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionAddResolvedDependencies: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .field("resolved_dependencies", .array(of: .json), .sql(.default("{}")) @@ -24,8 +24,8 @@ struct UpdateVersionAddResolvedDependencies: Migration { .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("resolved_dependencies") .update() } diff --git a/Sources/App/Migrations/034/UpdateVersionResolvedDependenciesNullable.swift b/Sources/App/Migrations/034/UpdateVersionResolvedDependenciesNullable.swift index 850ec2404..031d6dd11 100644 --- a/Sources/App/Migrations/034/UpdateVersionResolvedDependenciesNullable.swift +++ b/Sources/App/Migrations/034/UpdateVersionResolvedDependenciesNullable.swift @@ -15,9 +15,9 @@ import Fluent import SQLKit -struct UpdateVersionResolvedDependenciesNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("versions") +struct UpdateVersionResolvedDependenciesNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("versions") .deleteField("resolved_dependencies") .field("resolved_dependencies", .array(of: .json) @@ -25,8 +25,8 @@ struct UpdateVersionResolvedDependenciesNullable: Migration { .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("versions") + func revert(on database: Database) async throws { + try await database.schema("versions") .deleteField("resolved_dependencies") .field("resolved_dependencies", .array(of: .json), diff --git a/Sources/App/Migrations/035/UpdateBuildPendingToTriggered.swift b/Sources/App/Migrations/035/UpdateBuildPendingToTriggered.swift index d094078f2..7852d4f1e 100644 --- a/Sources/App/Migrations/035/UpdateBuildPendingToTriggered.swift +++ b/Sources/App/Migrations/035/UpdateBuildPendingToTriggered.swift @@ -15,8 +15,8 @@ import Fluent import SQLKit -struct UpdateBuildPendingToTriggered: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct UpdateBuildPendingToTriggered: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -24,10 +24,10 @@ struct UpdateBuildPendingToTriggered: Migration { """ UPDATE builds SET status = 'triggered' WHERE status = 'pending' """ - return db.raw(update).run() + try await db.raw(update).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -35,6 +35,6 @@ struct UpdateBuildPendingToTriggered: Migration { """ UPDATE builds SET status = 'pending' WHERE status = 'triggered' """ - return db.raw(update).run() + try await db.raw(update).run() } } diff --git a/Sources/App/Migrations/036/UpdatePackageScoreNotNullable.swift b/Sources/App/Migrations/036/UpdatePackageScoreNotNullable.swift index 6311339e5..fdf59ec29 100644 --- a/Sources/App/Migrations/036/UpdatePackageScoreNotNullable.swift +++ b/Sources/App/Migrations/036/UpdatePackageScoreNotNullable.swift @@ -15,38 +15,25 @@ import Fluent import SQLKit -struct UpdatePackageScoreNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdatePackageScoreNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( - #"UPDATE "packages" SET "score" = 0 WHERE "score" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "packages" ALTER COLUMN "score" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "packages" ALTER COLUMN "score" SET NOT NULL"# - ).run() - } + try await db.raw(#"UPDATE "packages" SET "score" = 0 WHERE "score" IS NULL"#).run() + try await db.raw(#"ALTER TABLE "packages" ALTER COLUMN "score" SET DEFAULT 0"#).run() + try await db.raw(#"ALTER TABLE "packages" ALTER COLUMN "score" SET NOT NULL"#).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( - #"ALTER TABLE "packages" ALTER COLUMN "score" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "packages" ALTER COLUMN "score" DROP DEFAULT"# - ).run() - } + try await db.raw(#"ALTER TABLE "packages" ALTER COLUMN "score" DROP NOT NULL"#).run() + try await db.raw(#"ALTER TABLE "packages" ALTER COLUMN "score" DROP DEFAULT"#).run() } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryCommitCountNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryCommitCountNotNullable.swift index 5530ff49a..d99718c0f 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryCommitCountNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryCommitCountNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryCommitCountNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryCommitCountNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "commit_count" = 0 WHERE "commit_count" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" SET DEFAULT 0"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "commit_count" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryForksNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryForksNotNullable.swift index 73161d4b3..91e9f0f14 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryForksNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryForksNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryForksNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryForksNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "forks" = 0 WHERE "forks" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "forks" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "forks" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "forks" SET DEFAULT 0"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "forks" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "forks" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "forks" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "forks" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryIsArchivedNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryIsArchivedNotNullable.swift index c09a3c73d..477ca8cde 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryIsArchivedNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryIsArchivedNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryIsArchivedNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryIsArchivedNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "is_archived" = false WHERE "is_archived" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" SET DEFAULT false"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" SET DEFAULT false"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_archived" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryIsInOrganizationNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryIsInOrganizationNotNullable.swift index 05f3e78b6..f211f9077 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryIsInOrganizationNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryIsInOrganizationNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryIsInOrganizationNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryIsInOrganizationNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "is_in_organization" = false WHERE "is_in_organization" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" SET DEFAULT false"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" SET DEFAULT false"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "is_in_organization" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryOpenIssuesNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryOpenIssuesNotNullable.swift index a7c3658b7..7c0192a04 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryOpenIssuesNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryOpenIssuesNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryOpenIssuesNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryOpenIssuesNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "open_issues" = 0 WHERE "open_issues" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" SET DEFAULT 0"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" DROP NOT NULL"# - ).run().flatMap { - db.raw( + ).run() + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "open_issues" DROP DEFAULT"# - ).run() - } + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryOpenPullRequestsNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryOpenPullRequestsNotNullable.swift index 8ea699f06..45d67ec81 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryOpenPullRequestsNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryOpenPullRequestsNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryOpenPullRequestsNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryOpenPullRequestsNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "open_pull_requests" = 0 WHERE "open_pull_requests" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" SET DEFAULT 0"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" SET NOT NULL"# + ).run() } } - - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "open_pull_requests" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/037/UpdateRepositoryStarsNotNullable.swift b/Sources/App/Migrations/037/UpdateRepositoryStarsNotNullable.swift index f0ec691bf..b8f921342 100644 --- a/Sources/App/Migrations/037/UpdateRepositoryStarsNotNullable.swift +++ b/Sources/App/Migrations/037/UpdateRepositoryStarsNotNullable.swift @@ -15,38 +15,35 @@ import Fluent import SQLKit -struct UpdateRepositoryStarsNotNullable: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.transaction { tx in +struct UpdateRepositoryStarsNotNullable: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"UPDATE "repositories" SET "stars" = 0 WHERE "stars" IS NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "stars" SET DEFAULT 0"# - ).run() - }.flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "stars" SET NOT NULL"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "stars" SET DEFAULT 0"# + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "stars" SET NOT NULL"# + ).run() } } - func revert(on database: Database) -> EventLoopFuture { - database.transaction { tx in + func revert(on database: Database) async throws { + try await database.transaction { tx in guard let db = tx as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw( + try await db.raw( #"ALTER TABLE "repositories" ALTER COLUMN "stars" DROP NOT NULL"# - ).run().flatMap { - db.raw( - #"ALTER TABLE "repositories" ALTER COLUMN "stars" DROP DEFAULT"# - ).run() - } + ).run() + try await db.raw( + #"ALTER TABLE "repositories" ALTER COLUMN "stars" DROP DEFAULT"# + ).run() } } } diff --git a/Sources/App/Migrations/038/AddLastActivityAtToRepositories.swift b/Sources/App/Migrations/038/AddLastActivityAtToRepositories.swift index 5b21962f1..3bae61722 100644 --- a/Sources/App/Migrations/038/AddLastActivityAtToRepositories.swift +++ b/Sources/App/Migrations/038/AddLastActivityAtToRepositories.swift @@ -16,13 +16,13 @@ import Fluent import SQLKit -struct AddLastActivityAtToRepositories: Migration { - func prepare(on database: Database) -> EventLoopFuture { +struct AddLastActivityAtToRepositories: AsyncMigration { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw(""" + try await db.raw(""" ALTER TABLE repositories ADD COLUMN last_activity_at TIMESTAMPTZ GENERATED ALWAYS AS ( GREATEST(last_commit_date, last_issue_closed_at, last_pull_request_closed_at) @@ -30,12 +30,12 @@ struct AddLastActivityAtToRepositories: Migration { """).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw(""" + try await db.raw(""" ALTER TABLE repositories DROP COLUMN last_activity_at; """).run() } diff --git a/Sources/App/Migrations/038/UpdateSearch3.swift b/Sources/App/Migrations/038/UpdateSearch3.swift index 795cce832..4a4a1a0c5 100644 --- a/Sources/App/Migrations/038/UpdateSearch3.swift +++ b/Sources/App/Migrations/038/UpdateSearch3.swift @@ -16,16 +16,16 @@ import Fluent import SQLKit -struct UpdateSearch3: Migration { +struct UpdateSearch3: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW search" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw(dropSQL).run() - .flatMap { db.raw(""" + try await db.raw(dropSQL).run() + try await db.raw(""" -- v4 CREATE MATERIALIZED VIEW search AS SELECT @@ -44,16 +44,16 @@ struct UpdateSearch3: Migration { JOIN repositories r ON r.package_id = p.id JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch - """).run() } + """).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw(dropSQL).run() - .flatMap { db.raw(""" + try await db.raw(dropSQL).run() + try await db.raw(""" -- v3 CREATE MATERIALIZED VIEW search AS SELECT @@ -71,6 +71,6 @@ struct UpdateSearch3: Migration { JOIN repositories r ON r.package_id = p.id JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch - """).run() } + """).run() } } diff --git a/Sources/App/Migrations/039/UpdateRecentReleases7.swift b/Sources/App/Migrations/039/UpdateRecentReleases7.swift index d81a89ce7..e9938d4b9 100644 --- a/Sources/App/Migrations/039/UpdateRecentReleases7.swift +++ b/Sources/App/Migrations/039/UpdateRecentReleases7.swift @@ -15,10 +15,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases7: Migration { +struct UpdateRecentReleases7: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -49,11 +49,11 @@ struct UpdateRecentReleases7: Migration { ORDER BY released_at DESC LIMIT 100; """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -82,7 +82,7 @@ struct UpdateRecentReleases7: Migration { order by released_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/040/UpdatePackageAppPlatformCompatibility.swift b/Sources/App/Migrations/040/UpdatePackageAppPlatformCompatibility.swift index 9ca79a819..a9ae69178 100644 --- a/Sources/App/Migrations/040/UpdatePackageAppPlatformCompatibility.swift +++ b/Sources/App/Migrations/040/UpdatePackageAppPlatformCompatibility.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdatePackageAppPlatformCompatibility: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("packages") +struct UpdatePackageAppPlatformCompatibility: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("packages") .field("platform_compatibility", .array(of: .string), .sql(.default("{}"))) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("packages") + func revert(on database: Database) async throws { + try await database.schema("packages") .deleteField("platform_compatibility") .update() } diff --git a/Sources/App/Migrations/041/UpdateSearch4.swift b/Sources/App/Migrations/041/UpdateSearch4.swift index ea4a619e2..26bee3065 100644 --- a/Sources/App/Migrations/041/UpdateSearch4.swift +++ b/Sources/App/Migrations/041/UpdateSearch4.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateSearch4: Migration { +struct UpdateSearch4: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW search" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -27,8 +27,8 @@ struct UpdateSearch4: Migration { // ** IMPORTANT ** // When updating the query underlying the materialized view, make sure to also // update the matching performance test in QueryPerformanceTests.test_Search_refresh! - return db.raw(dropSQL).run() - .flatMap { db.raw(""" + try await db.raw(dropSQL).run() + try await db.raw(""" -- v5 CREATE MATERIALIZED VIEW search AS SELECT @@ -48,16 +48,16 @@ struct UpdateSearch4: Migration { JOIN repositories r ON r.package_id = p.id JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch - """).run() } + """).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } - return db.raw(dropSQL).run() - .flatMap { db.raw(""" + try await db.raw(dropSQL).run() + try await db.raw(""" -- v4 CREATE MATERIALIZED VIEW search AS SELECT @@ -76,6 +76,6 @@ struct UpdateSearch4: Migration { JOIN repositories r ON r.package_id = p.id JOIN versions v ON v.package_id = p.id WHERE v.reference ->> 'branch' = r.default_branch - """).run() } + """).run() } } diff --git a/Sources/App/Migrations/042/UpdateRecentPackages4.swift b/Sources/App/Migrations/042/UpdateRecentPackages4.swift index 79e1fccea..e63f41576 100644 --- a/Sources/App/Migrations/042/UpdateRecentPackages4.swift +++ b/Sources/App/Migrations/042/UpdateRecentPackages4.swift @@ -16,10 +16,10 @@ import Fluent import SQLKit -struct UpdateRecentPackages4: Migration { +struct UpdateRecentPackages4: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_packages" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -49,11 +49,11 @@ struct UpdateRecentPackages4: Migration { created_at DESC LIMIT 500; """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -80,7 +80,7 @@ struct UpdateRecentPackages4: Migration { order by created_at desc limit 100 """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/042/UpdateRecentReleases8.swift b/Sources/App/Migrations/042/UpdateRecentReleases8.swift index f11f5d14c..5f767d08d 100644 --- a/Sources/App/Migrations/042/UpdateRecentReleases8.swift +++ b/Sources/App/Migrations/042/UpdateRecentReleases8.swift @@ -15,10 +15,10 @@ import Fluent import SQLKit -struct UpdateRecentReleases8: Migration { +struct UpdateRecentReleases8: AsyncMigration { let dropSQL: SQLQueryString = "DROP MATERIALIZED VIEW recent_releases" - func prepare(on database: Database) -> EventLoopFuture { + func prepare(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -50,11 +50,11 @@ struct UpdateRecentReleases8: Migration { released_at DESC LIMIT 500; """ - return db.raw(dropSQL).run() - .flatMap { db.raw(updatedViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(updatedViewSQL).run() } - func revert(on database: Database) -> EventLoopFuture { + func revert(on database: Database) async throws { guard let db = database as? SQLDatabase else { fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)") } @@ -85,7 +85,7 @@ struct UpdateRecentReleases8: Migration { ORDER BY released_at DESC LIMIT 100; """ - return db.raw(dropSQL).run() - .flatMap { db.raw(oldViewSQL).run() } + try await db.raw(dropSQL).run() + try await db.raw(oldViewSQL).run() } } diff --git a/Sources/App/Migrations/043/UpdateBuildAddRunnerId.swift b/Sources/App/Migrations/043/UpdateBuildAddRunnerId.swift index 91b4cd6c5..3b6b1c686 100644 --- a/Sources/App/Migrations/043/UpdateBuildAddRunnerId.swift +++ b/Sources/App/Migrations/043/UpdateBuildAddRunnerId.swift @@ -15,15 +15,15 @@ import Fluent -struct UpdateBuildAddRunnerId: Migration { - func prepare(on database: Database) -> EventLoopFuture { - database.schema("builds") +struct UpdateBuildAddRunnerId: AsyncMigration { + func prepare(on database: Database) async throws { + try await database.schema("builds") .field("runner_id", .string) .update() } - func revert(on database: Database) -> EventLoopFuture { - database.schema("builds") + func revert(on database: Database) async throws { + try await database.schema("builds") .deleteField("runner_id") .update() }