mirror of
https://git.sr.ht/~sircmpwn/hub.sr.ht
synced 2024-12-04 12:15:31 +01:00
Add SQL migration for GQL hooks
This is phase one, phase two will make several of these columns non-nullable once the webhooks are registered.
This commit is contained in:
parent
952f7043cb
commit
89fd4fea55
2 changed files with 69 additions and 3 deletions
|
@ -0,0 +1,50 @@
|
|||
"""Update schema for GQL hooks
|
||||
|
||||
Revision ID: 7bea74989938
|
||||
Revises: 9cfb231405a9
|
||||
Create Date: 2024-09-24 14:58:11.845757
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '7bea74989938'
|
||||
down_revision = '9cfb231405a9'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute("""
|
||||
CREATE TABLE user_service_webhooks (
|
||||
id serial PRIMARY KEY,
|
||||
git_hook_id integer,
|
||||
hg_hook_id integer,
|
||||
list_hook_id integer,
|
||||
todo_hook_id integer
|
||||
);
|
||||
|
||||
ALTER TABLE "user" ADD COLUMN
|
||||
user_hooks integer REFERENCES user_service_webhooks(id);
|
||||
|
||||
ALTER TABLE mailing_list
|
||||
ADD COLUMN remote_hook_id integer;
|
||||
ALTER TABLE source_repo
|
||||
ADD COLUMN remote_hook_id integer;
|
||||
ALTER TABLE tracker
|
||||
ADD COLUMN remote_hook_id integer;
|
||||
""")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute("""
|
||||
DROP TABLE "user" DROP COLUMN user_hooks integer;
|
||||
DROP TABLE user_service_webhooks;
|
||||
|
||||
ALTER TABLE mailing_list
|
||||
DROP COLUMN remote_hook_id integer;
|
||||
ALTER TABLE source_repo
|
||||
DROP COLUMN remote_hook_id integer;
|
||||
ALTER TABLE tracker
|
||||
DROP COLUMN remote_hook_id integer;
|
||||
""")
|
22
schema.sql
22
schema.sql
|
@ -4,6 +4,18 @@ CREATE TYPE visibility AS ENUM (
|
|||
'UNLISTED'
|
||||
);
|
||||
|
||||
CREATE TABLE user_service_webhooks (
|
||||
id serial PRIMARY KEY,
|
||||
-- git.sr.ht user webhook remote ID
|
||||
git_hook_id integer,
|
||||
-- hg.sr.ht user webhook remote ID
|
||||
hg_hook_id integer,
|
||||
-- lists.sr.ht user webhook remote ID
|
||||
list_hook_id integer,
|
||||
-- todo.sr.ht user webhook remote ID
|
||||
todo_hook_id integer
|
||||
);
|
||||
|
||||
CREATE TABLE "user" (
|
||||
id serial PRIMARY KEY,
|
||||
created timestamp without time zone NOT NULL,
|
||||
|
@ -18,7 +30,8 @@ CREATE TABLE "user" (
|
|||
oauth_token character varying(256),
|
||||
oauth_token_expires timestamp without time zone,
|
||||
oauth_token_scopes character varying,
|
||||
oauth_revocation_token character varying(256)
|
||||
oauth_revocation_token character varying(256),
|
||||
user_hooks integer REFERENCES user_service_webhooks(id)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX ix_user_username ON "user" USING btree (username);
|
||||
|
@ -53,7 +66,8 @@ CREATE TABLE mailing_list (
|
|||
owner_id integer NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||
name character varying(128) NOT NULL,
|
||||
description character varying,
|
||||
visibility visibility DEFAULT 'UNLISTED'::visibility NOT NULL
|
||||
visibility visibility DEFAULT 'UNLISTED'::visibility NOT NULL,
|
||||
remote_hook_id integer
|
||||
);
|
||||
|
||||
CREATE TABLE source_repo (
|
||||
|
@ -67,6 +81,7 @@ CREATE TABLE source_repo (
|
|||
description character varying,
|
||||
repo_type character varying NOT NULL,
|
||||
visibility visibility DEFAULT 'UNLISTED'::visibility NOT NULL,
|
||||
remote_hook_id integer,
|
||||
CONSTRAINT project_source_repo_unique UNIQUE (project_id, remote_id, repo_type)
|
||||
);
|
||||
|
||||
|
@ -82,7 +97,8 @@ CREATE TABLE tracker (
|
|||
owner_id integer NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
|
||||
name character varying(128) NOT NULL,
|
||||
description character varying,
|
||||
visibility visibility DEFAULT 'UNLISTED'::visibility NOT NULL
|
||||
visibility visibility DEFAULT 'UNLISTED'::visibility NOT NULL,
|
||||
remote_hook_id integer
|
||||
);
|
||||
|
||||
CREATE TABLE event (
|
||||
|
|
Loading…
Reference in a new issue