-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hummingbird-project/jobqueue-persist-migra…
…tions Use migration system for JobQueue and Persist frameworks
- Loading branch information
Showing
8 changed files
with
244 additions
and
93 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
Sources/HummingbirdJobsPostgres/Migrations/CreateJobQueue.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import HummingbirdPostgres | ||
import Logging | ||
@_spi(ConnectionPool) import PostgresNIO | ||
|
||
struct CreateJobQueue: HBPostgresMigration { | ||
func apply(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS _hb_pg_job_queue ( | ||
job_id uuid PRIMARY KEY, | ||
createdAt timestamp with time zone | ||
) | ||
""", | ||
logger: logger | ||
) | ||
try await connection.query( | ||
""" | ||
CREATE INDEX IF NOT EXISTS _hb_job_queueidx | ||
ON _hb_pg_job_queue (createdAt ASC) | ||
""", | ||
logger: logger | ||
) | ||
} | ||
|
||
func revert(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
"DROP TABLE _hb_pg_job_queue", | ||
logger: logger | ||
) | ||
} | ||
|
||
var name: String { "_Create_JobQueue_Table_" } | ||
var group: HBMigrationGroup { .jobQueue } | ||
} |
48 changes: 48 additions & 0 deletions
48
Sources/HummingbirdJobsPostgres/Migrations/CreateJobs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import HummingbirdPostgres | ||
import Logging | ||
@_spi(ConnectionPool) import PostgresNIO | ||
|
||
struct CreateJobs: HBPostgresMigration { | ||
func apply(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS _hb_pg_jobs ( | ||
id uuid PRIMARY KEY, | ||
job bytea, | ||
status smallint, | ||
lastModified TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP | ||
) | ||
""", | ||
logger: logger | ||
) | ||
} | ||
|
||
func revert(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
"DROP TABLE _hb_pg_jobs", | ||
logger: logger | ||
) | ||
} | ||
|
||
var name: String { "_Create_Jobs_Table_" } | ||
var group: HBMigrationGroup { .jobQueue } | ||
} | ||
|
||
extension HBMigrationGroup { | ||
/// JobQueue migration group | ||
public static var jobQueue: Self { .init("_hb_jobqueue") } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Logging | ||
@_spi(ConnectionPool) import PostgresNIO | ||
|
||
struct CreatePersistTable: HBPostgresMigration { | ||
func apply(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
""" | ||
CREATE TABLE IF NOT EXISTS _hb_pg_persist ( | ||
"id" text PRIMARY KEY, | ||
"data" json NOT NULL, | ||
"expires" timestamp with time zone NOT NULL | ||
) | ||
""", | ||
logger: logger | ||
) | ||
} | ||
|
||
func revert(connection: PostgresConnection, logger: Logger) async throws { | ||
try await connection.query( | ||
"DROP TABLE _hb_pg_persist", | ||
logger: logger | ||
) | ||
} | ||
|
||
var name: String { "_Create_Persist_Table_" } | ||
var group: HBMigrationGroup { .persist } | ||
} | ||
|
||
extension HBMigrationGroup { | ||
/// Persist driver migration group | ||
public static var persist: Self { .init("_hb_pg_persist") } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.