-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path2024_07_26_1356-21009df4f5f5_introduce_third_party_clients.py
90 lines (82 loc) · 2.73 KB
/
2024_07_26_1356-21009df4f5f5_introduce_third_party_clients.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
"""Introduce third-party clients
Revision ID: 21009df4f5f5
Revises: 4c13fdf8868d
Create Date: 2024-07-26 13:56:21.385422
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "21009df4f5f5"
down_revision = "4c13fdf8868d"
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"service_clients",
sa.Column("secret", sa.String(length=128), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("description", sa.String(), nullable=False),
sa.Column("endpoint", sa.String(), nullable=False),
sa.Column("user_id", sa.Uuid(), nullable=True),
sa.Column("created", sa.DateTime(), nullable=False),
sa.Column("id", sa.Uuid(), nullable=False),
sa.ForeignKeyConstraint(
["user_id"],
["service_users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"service_auth_token_requests",
sa.Column("user_id", sa.Uuid(), nullable=True),
sa.Column("expiration", sa.DateTime(), nullable=False),
sa.Column("created", sa.DateTime(), nullable=False),
sa.Column("client_id", sa.Uuid(), nullable=True),
sa.Column(
"scope", postgresql.JSONB(astext_type=sa.Text()), nullable=False
),
sa.Column("id", sa.Uuid(), nullable=False),
sa.ForeignKeyConstraint(
["client_id"], ["service_clients.id"], ondelete="CASCADE"
),
sa.ForeignKeyConstraint(
["user_id"],
["service_users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.add_column(
"service_auth_tokens", sa.Column("client_id", sa.Uuid(), nullable=True)
)
op.add_column(
"service_auth_tokens",
sa.Column(
"scope",
postgresql.JSONB(astext_type=sa.Text()),
server_default="[]",
nullable=False,
),
)
op.create_foreign_key(
"service_auth_tokens_client_id_fkey",
"service_auth_tokens",
"service_clients",
["client_id"],
["id"],
ondelete="CASCADE",
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"service_auth_tokens_client_id_fkey",
"service_auth_tokens",
type_="foreignkey",
)
op.drop_column("service_auth_tokens", "scope")
op.drop_column("service_auth_tokens", "client_id")
op.drop_table("service_auth_token_requests")
op.drop_table("service_clients")
# ### end Alembic commands ###