~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/alembic/versions/82ff5fc58b75_add_user_webhook_tables.py -rw-r--r-- 2.9 KiB
72548bd7Drew DeVault API: Updates per core-go auth changes 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Add user webhook tables

Revision ID: 82ff5fc58b75
Revises: 18a2c6a540bc
Create Date: 2018-12-31 12:27:28.960511

"""

# revision identifiers, used by Alembic.
revision = '82ff5fc58b75'
down_revision = '18a2c6a540bc'

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils as sau


def upgrade():
    op.drop_table('webhook_delivery')
    op.drop_table('webhook')
    op.create_table('user_webhook_subscription',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('created', sa.DateTime, nullable=False),
        sa.Column('url', sa.Unicode(2048), nullable=False),
        sa.Column('events', sa.Unicode, nullable=False),
        sa.Column('user_id', sa.Integer,
            sa.ForeignKey("user.id")),
        sa.Column('client_id', sa.Integer,
            sa.ForeignKey("oauthclient.id")))
    op.create_table('user_webhook_delivery',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('uuid', sau.UUIDType, nullable=False),
        sa.Column('created', sa.DateTime, nullable=False),
        sa.Column('event', sa.Unicode(256), nullable=False),
        sa.Column('url', sa.Unicode(2048), nullable=False),
        sa.Column('payload', sa.Unicode(16384), nullable=False),
        sa.Column('payload_headers', sa.Unicode(16384), nullable=False),
        sa.Column('response', sa.Unicode(16384)),
        sa.Column('response_status', sa.Integer, nullable=False),
        sa.Column('response_headers', sa.Unicode(16384)),
        sa.Column('subscription_id', sa.Integer,
            sa.ForeignKey("user_webhook_subscription.id")))


def downgrade():
    op.drop_table('user_webhook_subscription')
    op.drop_table('user_webhook_delivery')
    op.create_table('webhook',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('created', sa.DateTime, nullable=False),
        sa.Column('updated', sa.DateTime, nullable=False),
        sa.Column('user_id', sa.Integer, sa.ForeignKey("user.id")),
        sa.Column('client_id', sa.Integer,
            sa.ForeignKey("oauthclient.id", ondelete="CASCADE")),
        sa.Column('url', sa.Unicode(2048), nullable=False),
        sa.Column('events', sa.Unicode, nullable=False))
    op.create_table('webhook_delivery',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('created', sa.DateTime, nullable=False),
        sa.Column('event', sa.Unicode(256), nullable=False),
        sa.Column('webhook_id', sa.Integer,
            sa.ForeignKey("webhook.id", ondelete="CASCADE"),
            nullable=False),
        sa.Column('url', sa.Unicode(2048), nullable=False),
        sa.Column('payload', sa.Unicode(16384), nullable=False),
        sa.Column('payload_headers', sa.Unicode(16384), nullable=False),
        sa.Column('response', sa.Unicode(16384), nullable=False),
        sa.Column('response_status', sa.Integer, nullable=False),
        sa.Column('response_headers', sa.Unicode(16384), nullable=False))