-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce simple migration framework
- Loading branch information
Showing
3 changed files
with
97 additions
and
37 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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,43 @@ | ||
import typing as t | ||
|
||
from psycopg.sql import Identifier, SQL, Composed | ||
from textwrap import dedent | ||
|
||
|
||
def get_migrations( | ||
jobs_table: Identifier, | ||
stats_table: Identifier, | ||
) -> t.List[t.List[Composed]]: | ||
return [ | ||
[ | ||
SQL( | ||
dedent(""" | ||
CREATE TABLE IF NOT EXISTS {jobs_table} ( | ||
key TEXT PRIMARY KEY, | ||
lock_key SERIAL NOT NULL, | ||
job BYTEA NOT NULL, | ||
queue TEXT NOT NULL, | ||
status TEXT NOT NULL, | ||
priority SMALLINT NOT NULL DEFAULT 0, | ||
group_key TEXT, | ||
scheduled BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()), | ||
expire_at BIGINT | ||
); | ||
""") | ||
).format(jobs_table=jobs_table), | ||
SQL( | ||
dedent(""" | ||
CREATE INDEX IF NOT EXISTS saq_jobs_dequeue_idx ON {jobs_table} (status, queue, scheduled); | ||
""") | ||
).format(jobs_table=jobs_table), | ||
SQL( | ||
dedent(""" | ||
CREATE TABLE IF NOT EXISTS {stats_table} ( | ||
worker_id TEXT PRIMARY KEY, | ||
stats JSONB, | ||
expire_at BIGINT | ||
); | ||
""") | ||
).format(stats_table=stats_table), | ||
], | ||
] |