06337a1905a5_upgrade_customer_usaha.py
3.37 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
"""upgrade customer usaha
Revision ID: 06337a1905a5
Revises: cc2e4a0aad1e
Create Date: 2024-11-15 16:35:40.192189
"""
# revision identifiers, used by Alembic.
from opensipkd.pjdl.models import PjdlWp, PjdlKecamatan, PjdlKelurahan, DBSession, Base
revision = '06337a1905a5'
down_revision = 'cc2e4a0aad1e'
branch_labels = None
depends_on = None
import sqlalchemy as sa
from alembic import op
def upgrade():
context = op.get_context()
helpers = context.opts['helpers']
schema="pad"
helpers.fields_update("pad_customer_usaha", "jatuhtempo", sa.DateTime(timezone=False), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin1", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin1no", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin1tgl", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin1tglakhir", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin2", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin2no", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin2tgl", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin2tglakhir", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin3", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin3no", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin3tgl", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin3tglakhir", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin4", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin4no", sa.String(100), schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin4tgl", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer_usaha", "ijin4tglakhir", sa.DateTime, schema=schema)
helpers.fields_update("pad_customer", "kd_restojmlmeja", sa.Integer, schema=schema)
helpers.fields_update(
"pad_customer", "kd_restojmlkursi", sa.Integer, schema=schema)
engine = op.get_bind()
DBSession.configure(bind=engine)
Base.metadata.bind = engine
query = PjdlWp.query().filter(PjdlWp.npwpd == None)
for row in query.all():
formno = row.formno
kecamatan = PjdlKecamatan.query_id(row.kecamatan_id).first()
kelurahan = PjdlKelurahan.query_id(row.kelurahan_id).first()
row.npwpd = "".join(
[str(row.rp), str(row.pb), str(formno).zfill(6), kecamatan.kode, kelurahan.kode])
print(row.npwpd)
DBSession.add(row)
DBSession.flush()
if helpers.table_has_column("users", "userid", schema="public"):
user_table = sa.Table(
'users', sa.MetaData(),
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('userid', sa.String(50)),
)
query = engine.execute(
sa.select(user_table.c.id, user_table.c.userid).filter(user_table.c.userid != None))
for row in query.all():
wps = PjdlWp.query().filter(PjdlWp.npwpd == row.userid)
for wp in wps:
if not wp.user_id:
wp.user_id = row.id
DBSession.add(wp)
DBSession.flush()
def downgrade():
pass