-
Notifications
You must be signed in to change notification settings - Fork 0
/
12406d0bbd1b_add_third_party_client_company_table.py
114 lines (106 loc) · 3.39 KB
/
12406d0bbd1b_add_third_party_client_company_table.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""add third_party_client_company table
Revision ID: 12406d0bbd1b
Revises: 52434978c99e
Create Date: 2022-12-14 11:18:10.991713
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "12406d0bbd1b"
down_revision = "52434978c99e"
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
"third_party_api_key",
sa.Column("creation_time", sa.DateTime(), nullable=False),
sa.Column("client_id", sa.Integer(), nullable=False),
sa.Column("api_key", sa.String(length=255), nullable=False),
sa.Column("id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["client_id"],
["oauth2_client.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_third_party_api_key_client_id"),
"third_party_api_key",
["client_id"],
unique=False,
)
op.create_table(
"third_party_client_company",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("creation_time", sa.DateTime(), nullable=False),
sa.Column("client_id", sa.Integer(), nullable=False),
sa.Column("company_id", sa.Integer(), nullable=False),
sa.Column("dismissed_at", sa.DateTime(), nullable=True),
sa.Column(
"dismiss_context",
postgresql.JSONB(none_as_null=True, astext_type=sa.Text()),
nullable=True,
),
sa.Column("dismiss_author_id", sa.Integer(), nullable=True),
sa.CheckConstraint(
"((dismissed_at is not null)::bool = (dismiss_author_id is not null)::bool)",
name="non_nullable_dismiss_info",
),
sa.ForeignKeyConstraint(
["client_id"],
["oauth2_client.id"],
),
sa.ForeignKeyConstraint(
["company_id"],
["company.id"],
),
sa.ForeignKeyConstraint(
["dismiss_author_id"],
["user.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_third_party_client_company_client_id"),
"third_party_client_company",
["client_id"],
unique=False,
)
op.create_index(
op.f("ix_third_party_client_company_company_id"),
"third_party_client_company",
["company_id"],
unique=False,
)
op.create_index(
op.f("ix_third_party_client_company_dismiss_author_id"),
"third_party_client_company",
["dismiss_author_id"],
unique=False,
)
op.add_column(
"oauth2_client",
sa.Column("whitelist_ips", sa.ARRAY(sa.String()), nullable=True),
)
def downgrade():
op.drop_column("oauth2_client", "whitelist_ips")
op.drop_index(
op.f("ix_third_party_client_company_dismiss_author_id"),
table_name="third_party_client_company",
)
op.drop_index(
op.f("ix_third_party_client_company_company_id"),
table_name="third_party_client_company",
)
op.drop_index(
op.f("ix_third_party_client_company_client_id"),
table_name="third_party_client_company",
)
op.drop_table("third_party_client_company")
op.drop_index(
op.f("ix_third_party_api_key_client_id"),
table_name="third_party_api_key",
)
op.drop_table("third_party_api_key")
# ### end Alembic commands ###