-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1729015196af_implement_soft_delete_translations.py
213 lines (201 loc) · 5.82 KB
/
1729015196af_implement_soft_delete_translations.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
"""implement soft delete for story_translations
Revision ID: 1729015196af
Revises: 5a1dbdb0d816
Create Date: 2021-10-19 04:26:37.069546
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "1729015196af"
down_revision = "5a1dbdb0d816"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
### Update story_translations
op.add_column(
"story_translations",
sa.Column("is_deleted", sa.Boolean(), default=False, nullable=False),
)
op.drop_constraint(
u"story_translations_ibfk_1", "story_translations", type_="foreignkey"
)
op.drop_constraint(
u"story_translations_ibfk_2", "story_translations", type_="foreignkey"
)
op.drop_constraint(
u"story_translations_ibfk_3", "story_translations", type_="foreignkey"
)
op.rename_table("story_translations", "story_translations_all")
op.create_foreign_key(
u"story_translations_all_ibfk_1",
"story_translations_all",
"users",
["reviewer_id"],
["id"],
)
op.create_foreign_key(
u"story_translations_all_ibfk_2",
"story_translations_all",
"users",
["translator_id"],
["id"],
)
op.create_foreign_key(
u"story_translations_all_ibfk_3",
"story_translations_all",
"stories",
["story_id"],
["id"],
)
active_translations_view = """
CREATE VIEW story_translations
AS
SELECT * from story_translations_all
WHERE is_deleted=0;
"""
op.execute(active_translations_view)
### Update story_translation_contents
op.add_column(
"story_translation_contents",
sa.Column("is_deleted", sa.Boolean(), default=False, nullable=False),
)
op.drop_constraint(
u"story_translation_contents_ibfk_1",
"story_translation_contents",
type_="foreignkey",
)
op.rename_table("story_translation_contents", "story_translation_contents_all")
op.create_foreign_key(
u"story_translation_contents_all_ibfk_1",
"story_translation_contents_all",
"story_translations_all",
["story_translation_id"],
["id"],
)
active_translation_contents_view = """
CREATE VIEW story_translation_contents
AS
SELECT * from story_translation_contents_all
WHERE is_deleted=0;
"""
op.execute(active_translation_contents_view)
### Update comments
op.add_column(
"comments",
sa.Column("is_deleted", sa.Boolean(), default=False, nullable=False),
)
op.drop_constraint(
u"comments_ibfk_1",
"comments",
type_="foreignkey",
)
op.drop_constraint(
u"comments_ibfk_2",
"comments",
type_="foreignkey",
)
op.rename_table("comments", "comments_all")
op.create_foreign_key(
u"comments_all_ibfk_1",
"comments_all",
"story_translation_contents_all",
["story_translation_content_id"],
["id"],
)
op.create_foreign_key(
u"comments_all_ibfk_2",
"comments_all",
"users",
["user_id"],
["id"],
)
active_comments_view = """
CREATE VIEW comments
AS
SELECT * from comments_all
WHERE is_deleted=0;
"""
op.execute(active_comments_view)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
### Update story_translations
op.execute("DROP VIEW story_translations")
op.drop_constraint(
u"story_translations_all_ibfk_1", "story_translations_all", type_="foreignkey"
)
op.drop_constraint(
u"story_translations_all_ibfk_2", "story_translations_all", type_="foreignkey"
)
op.drop_constraint(
u"story_translations_all_ibfk_3", "story_translations_all", type_="foreignkey"
)
op.rename_table("story_translations_all", "story_translations")
op.create_foreign_key(
u"story_translations_ibfk_1",
"story_translations",
"users",
["reviewer_id"],
["id"],
)
op.create_foreign_key(
u"story_translations_ibfk_2",
"story_translations",
"users",
["translator_id"],
["id"],
)
op.create_foreign_key(
u"story_translations_ibfk_3",
"story_translations",
"stories",
["story_id"],
["id"],
)
op.drop_column("story_translations", "is_deleted")
### Update story_translation_contents
op.execute("DROP VIEW story_translation_contents")
op.drop_constraint(
u"story_translation_contents_all_ibfk_1",
"story_translation_contents_all",
type_="foreignkey",
)
op.rename_table("story_translation_contents_all", "story_translation_contents")
op.create_foreign_key(
u"story_translation_contents_ibfk_1",
"story_translation_contents",
"story_translations",
["story_translation_id"],
["id"],
)
op.drop_column("story_translation_contents", "is_deleted")
### Update comments
op.execute("DROP VIEW comments")
op.drop_constraint(
u"comments_all_ibfk_1",
"comments_all",
type_="foreignkey",
)
op.drop_constraint(
u"comments_all_ibfk_2",
"comments_all",
type_="foreignkey",
)
op.rename_table("comments_all", "comments")
op.create_foreign_key(
u"comments_ibfk_1",
"comments",
"story_translation_contents",
["story_translation_content_id"],
["id"],
)
op.create_foreign_key(
u"comments_ibfk_2",
"comments",
"users",
["user_id"],
["id"],
)
op.drop_column("comments", "is_deleted")
# ### end Alembic commands ###