-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use migration system for JobQueue and Persist frameworks #8
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
49b26a9
Add migrations for HBPostgresJobQueue
adam-fowler cace687
Add persist migration
adam-fowler 28a831e
Set job queue group
adam-fowler 77ae661
Persist driver uses migrations
adam-fowler 7c0470f
Set migration group for jobs queue and persist
adam-fowler 3c94c17
Add Job last modified
adam-fowler 345f0b6
Revert migrations in tests, don't flag migrations as complete in a re…
adam-fowler 1de57aa
Set job queue label as test name
adam-fowler 2936688
Hopefully fix testRerunAtStartup
adam-fowler f027180
Update log level for onInit logging
adam-fowler 7b45b60
Rename tables to include pg
adam-fowler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this better off as such: