-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2022-11-07_12e97fac48b2_update_intake_model.py
206 lines (195 loc) · 6.72 KB
/
2022-11-07_12e97fac48b2_update_intake_model.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
"""update intake model
Revision ID: 12e97fac48b2
Revises: 5fff1dc51c07
Create Date: 2022-11-07 00:37:45.389536
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "12e97fac48b2"
down_revision = "5fff1dc51c07"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# https://stackoverflow.com/questions/37848815/sqlalchemy-postgresql-enum-does-not-create-type-on-db-migrate
cpin_file_type = postgresql.ENUM("INVESTIGATION", "ONGOING", name="cpin_file_type")
cpin_file_type.create(op.get_bind())
op.add_column(
"intakes",
sa.Column(
"cpin_file_type",
cpin_file_type,
nullable=False,
),
)
# https://stackoverflow.com/questions/37848815/sqlalchemy-postgresql-enum-does-not-create-type-on-db-migrate
intake_status = postgresql.ENUM(
"SUBMITTED", "PENDING", "ACTIVE", "ARCHIVED", name="intake_status"
)
intake_status.create(op.get_bind())
op.add_column(
"intakes",
sa.Column(
"intake_status",
intake_status,
nullable=True,
),
)
op.add_column(
"intakes", sa.Column("referring_worker_contact", sa.String(), nullable=False)
)
op.add_column(
"intakes", sa.Column("referring_worker_name", sa.String(), nullable=False)
)
op.add_column(
"intakes", sa.Column("scheduling_requirements", sa.String(), nullable=False)
)
op.add_column(
"intakes", sa.Column("suggested_start_date", sa.Date(), nullable=False)
)
op.add_column(
"intakes", sa.Column("transportation_requirements", sa.String(), nullable=False)
)
op.add_column("intakes", sa.Column("user_id", sa.Integer(), nullable=False))
op.alter_column(
"intakes", "court_order_file", existing_type=sa.VARCHAR(), nullable=False
)
op.alter_column(
"intakes",
"court_status",
existing_type=postgresql.ENUM(
"INTERIM_CARE",
"FINAL_ORDER_FOR_SOCIETY_CARE",
"EXTENDED_SOCIETY_CARE",
"SUPERVISION_ORDER",
"KIN_SERVICE_PLACEMENT",
"LIVING_WITH_BIO_FAMILY",
"OTHER",
name="intakes_court_status",
),
nullable=False,
)
op.alter_column(
"intakes", "cpin_number", existing_type=sa.VARCHAR(), nullable=False
)
op.alter_column(
"intakes", "family_name", existing_type=sa.VARCHAR(), nullable=False
)
op.alter_column("intakes", "referral_date", existing_type=sa.DATE(), nullable=False)
op.drop_constraint(
"intakes_referring_worker_id_fkey", "intakes", type_="foreignkey"
)
op.create_foreign_key(None, "intakes", "users", ["user_id"], ["id"])
op.drop_column("intakes", "is_investigation")
op.drop_column("intakes", "case_date")
op.drop_column("intakes", "is_ongoing")
op.drop_column("intakes", "court_order")
op.drop_column("intakes", "is_court_involved")
op.drop_column("intakes", "is_accepted")
op.drop_column("intakes", "is_first_nation_heritage")
op.drop_column("intakes", "access_type")
op.drop_column("intakes", "access_start_date")
op.drop_column("intakes", "referring_worker_id")
op.drop_column("intakes", "family_strengths")
op.drop_column("intakes", "transportation")
op.drop_column("intakes", "limitations")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"intakes",
sa.Column("limitations", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column("transportation", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column("family_strengths", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column(
"referring_worker_id", sa.INTEGER(), autoincrement=False, nullable=True
),
)
op.add_column(
"intakes",
sa.Column("access_start_date", sa.DATE(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column("access_type", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column(
"is_first_nation_heritage", sa.BOOLEAN(), autoincrement=False, nullable=True
),
)
op.add_column(
"intakes",
sa.Column("is_accepted", sa.BOOLEAN(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column(
"is_court_involved", sa.BOOLEAN(), autoincrement=False, nullable=True
),
)
op.add_column(
"intakes",
sa.Column("court_order", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes",
sa.Column("is_ongoing", sa.BOOLEAN(), autoincrement=False, nullable=True),
)
op.add_column(
"intakes", sa.Column("case_date", sa.DATE(), autoincrement=False, nullable=True)
)
op.add_column(
"intakes",
sa.Column("is_investigation", sa.BOOLEAN(), autoincrement=False, nullable=True),
)
op.drop_constraint(None, "intakes", type_="foreignkey")
op.create_foreign_key(
"intakes_referring_worker_id_fkey",
"intakes",
"users",
["referring_worker_id"],
["id"],
)
op.alter_column("intakes", "referral_date", existing_type=sa.DATE(), nullable=True)
op.alter_column("intakes", "family_name", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column("intakes", "cpin_number", existing_type=sa.VARCHAR(), nullable=True)
op.alter_column(
"intakes",
"court_status",
existing_type=postgresql.ENUM(
"INTERIM_CARE",
"FINAL_ORDER_FOR_SOCIETY_CARE",
"EXTENDED_SOCIETY_CARE",
"SUPERVISION_ORDER",
"KIN_SERVICE_PLACEMENT",
"LIVING_WITH_BIO_FAMILY",
"OTHER",
name="intakes_court_status",
),
nullable=True,
)
op.alter_column(
"intakes", "court_order_file", existing_type=sa.VARCHAR(), nullable=True
)
op.drop_column("intakes", "user_id")
op.drop_column("intakes", "transportation_requirements")
op.drop_column("intakes", "suggested_start_date")
op.drop_column("intakes", "scheduling_requirements")
op.drop_column("intakes", "referring_worker_name")
op.drop_column("intakes", "referring_worker_contact")
op.drop_column("intakes", "intake_status")
op.drop_column("intakes", "cpin_file_type")
# ### end Alembic commands ###