a01dc09faec0_upgrade_user.py
3.14 KB
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
"""upgrade user
Revision ID: a01dc09faec0
Revises:
Create Date: 2023-03-06 20:23:58.698148
"""
# revision identifiers, used by Alembic.
revision = 'a01dc09faec0'
down_revision = None
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
src_schema = 'app'
tables = ['apps', 'app_status',
'users', 'groups', "modules", "group_modules", "user_groups",
'user_uptd']
context = op.get_context()
helpers = context.opts['helpers']
for t in tables:
if helpers.has_table(t, src_schema):
context.execute(f'alter table {src_schema}.{t} set schema public')
schema = 'public'
if not helpers.table_has_column('users', 'user_name', schema):
op.add_column('users',
sa.Column('user_name', sa.String(128)), schema=schema)
if not helpers.table_has_column('users', 'user_password', schema):
op.add_column('users',
sa.Column('user_password', sa.String(256)), schema=schema)
if not helpers.table_has_column('users', 'email', schema):
op.add_column('users',
sa.Column('email', sa.String(100)), schema=schema)
if not helpers.table_has_column('users', 'status', schema):
op.add_column('users',
sa.Column('status', sa.SmallInteger), schema=schema)
if not helpers.table_has_column('users', 'security_code', schema):
op.add_column('users',
sa.Column('security_code', sa.String(256)), schema=schema)
if not helpers.table_has_column('users', 'last_login_date', schema):
op.add_column('users',
sa.Column('last_login_date', sa.TIMESTAMP(timezone=True)), schema=schema)
if not helpers.table_has_column('users', 'registered_date', schema):
op.add_column('users',
sa.Column('registered_date', sa.TIMESTAMP(timezone=True)), schema=schema)
if not helpers.table_has_column('users', 'security_code_date', schema):
op.add_column('users',
sa.Column('security_code_date',
sa.TIMESTAMP(timezone=True)),
schema=schema)
if not helpers.table_has_column('users', 'api_key', schema):
op.add_column(
'users', sa.Column('api_key', sa.String(256)), schema=schema)
if not helpers.table_has_column('users', 'partner_id', schema):
op.add_column(
'users', sa.Column('partner_id', sa.Integer), schema=schema)
if not helpers.table_has_column('users', 'company_id', schema):
op.add_column(
'users', sa.Column('company_id', sa.Integer), schema=schema)
if not helpers.has_table("alembic_ziggurat_foundations_version", "public"):
table = op.create_table(
"alembic_ziggurat_foundations_version", sa.Column(
"version_num", sa.String(64)),
schema="public")
else:
table = sa.sql.table(
"alembic_ziggurat_foundations_version", sa.sql.column("version_num", sa.String(64)))
op.bulk_insert(table, [{"version_num": "613e7c11dead"}])
def downgrade():
pass