~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/alembic/versions/839e4a29751a_add_cascades_for_oauth_foreign_keys.py -rw-r--r-- 3.5 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
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
"""Add cascades for oauth foreign keys

Revision ID: 839e4a29751a
Revises: 5a5fda549d80
Create Date: 2018-06-16 11:22:28.518692

"""

# revision identifiers, used by Alembic.
revision = '839e4a29751a'
down_revision = '5a5fda549d80'

from alembic import op
import sqlalchemy as sa


def upgrade():
    op.drop_constraint(
            constraint_name="revocationurl_client_id_fkey",
            table_name="revocationurl",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="revocationurl_client_id_fkey",
            source_table="revocationurl",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"],
            ondelete="CASCADE")
    op.drop_constraint(
            constraint_name="revocationurl_token_id_fkey",
            table_name="revocationurl",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="revocationurl_token_id_fkey",
            source_table="revocationurl",
            referent_table="oauthtoken",
            local_cols=["token_id"],
            remote_cols=["id"],
            ondelete="CASCADE")
    op.drop_constraint(
            constraint_name="oauthtoken_client_id_fkey",
            table_name="oauthtoken",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="oauthtoken_client_id_fkey",
            source_table="oauthtoken",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"],
            ondelete="CASCADE")
    op.drop_constraint(
            constraint_name="delegatedscope_client_id_fkey",
            table_name="delegatedscope",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="delegatedscope_client_id_fkey",
            source_table="delegatedscope",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"],
            ondelete="CASCADE")


def downgrade():
    op.drop_constraint(
            constraint_name="revocationurl_client_id_fkey",
            table_name="revocationurl",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="revocationurl_client_id_fkey",
            source_table="revocationurl",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"])
    op.drop_constraint(
            constraint_name="revocationurl_token_id_fkey",
            table_name="revocationurl",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="revocationurl_token_id_fkey",
            source_table="revocationurl",
            referent_table="oauthtoken",
            local_cols=["token_id"],
            remote_cols=["id"])
    op.drop_constraint(
            constraint_name="oauthtoken_client_id_fkey",
            table_name="oauthtoken",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="oauthtoken_client_id_fkey",
            source_table="oauthtoken",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"])
    op.drop_constraint(
            constraint_name="delegatedscope_client_id_fkey",
            table_name="delegatedscope",
            type_="foreignkey")
    op.create_foreign_key(
            constraint_name="delegatedscope_client_id_fkey",
            source_table="delegatedscope",
            referent_table="oauthclient",
            local_cols=["client_id"],
            remote_cols=["id"])