forked from DigiFi/digifi-BankToProductCore
[add]: migration
This commit is contained in:
+58
-7
@@ -1,19 +1,37 @@
|
|||||||
"""Migration on Mon Jun 30 13:57:38 UTC 2025
|
"""empty message
|
||||||
|
|
||||||
Revision ID: bf4d402e5303
|
Revision ID: 33e09efd85e3
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2025-06-30 13:57:46.908628
|
Create Date: 2025-07-03 14:07:14.424548
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import literal_column
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = 'bf4d402e5303'
|
revision = '33e09efd85e3'
|
||||||
down_revision = None
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
sequences_and_triggers = [
|
||||||
|
("transactions", "transactions_seq", "trg_transactions_id"),
|
||||||
|
("transaction_offers", "transaction_offers_seq", "trg_transaction_offers_id"),
|
||||||
|
("salaries", "salaries_seq", "trg_salaries_id"),
|
||||||
|
("repayments_data", "repayments_data_seq", "trg_repayments_data_id"),
|
||||||
|
("repayments", "repayments_seq", "trg_repayments_id"),
|
||||||
|
("rac_checks", "rac_checks_seq", "trg_rac_checks_id"),
|
||||||
|
("loans", "loans_seq", "trg_loans_id"),
|
||||||
|
(
|
||||||
|
"loan_repayment_schedules",
|
||||||
|
"loan_repayment_schedules_seq",
|
||||||
|
"trg_loan_repayment_schedules_id",
|
||||||
|
),
|
||||||
|
("loan_charges", "loan_charges_seq", "trg_loan_charges_id"),
|
||||||
|
("charges", "charges_seq", "trg_charges_id"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
@@ -92,7 +110,6 @@ def upgrade():
|
|||||||
sa.Column('continuous_fee', sa.Float(), nullable=True),
|
sa.Column('continuous_fee', sa.Float(), nullable=True),
|
||||||
sa.Column('upfront_fee', sa.Float(), nullable=True),
|
sa.Column('upfront_fee', sa.Float(), nullable=True),
|
||||||
sa.Column('repayment_amount', sa.Float(), nullable=True),
|
sa.Column('repayment_amount', sa.Float(), nullable=True),
|
||||||
sa.Column('balance', sa.Float(), nullable=True),
|
|
||||||
sa.Column('installment_amount', sa.Float(), nullable=True),
|
sa.Column('installment_amount', sa.Float(), nullable=True),
|
||||||
sa.Column('status', sa.String(length=20), nullable=True),
|
sa.Column('status', sa.String(length=20), nullable=True),
|
||||||
sa.Column('tenor', sa.Integer(), nullable=True),
|
sa.Column('tenor', sa.Integer(), nullable=True),
|
||||||
@@ -133,7 +150,7 @@ def upgrade():
|
|||||||
sa.Column('transaction_id', sa.String(length=50), nullable=False),
|
sa.Column('transaction_id', sa.String(length=50), nullable=False),
|
||||||
sa.Column('customer_id', sa.String(length=50), nullable=False),
|
sa.Column('customer_id', sa.String(length=50), nullable=False),
|
||||||
sa.Column('account_id', sa.String(length=50), nullable=False),
|
sa.Column('account_id', sa.String(length=50), nullable=False),
|
||||||
sa.Column('rac_response', sa.String(length=225), nullable=False),
|
sa.Column('rac_response', sa.Text(), nullable=False),
|
||||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
||||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
@@ -208,7 +225,37 @@ def upgrade():
|
|||||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
)
|
)
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
for table, seq, trg in sequences_and_triggers:
|
||||||
|
op.execute(
|
||||||
|
text(
|
||||||
|
f"""
|
||||||
|
BEGIN
|
||||||
|
EXECUTE IMMEDIATE 'CREATE SEQUENCE {seq} START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE';
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
IF SQLCODE != -955 THEN RAISE; END IF;
|
||||||
|
END;
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
op.execute(
|
||||||
|
text(
|
||||||
|
f"""
|
||||||
|
CREATE OR REPLACE TRIGGER {trg}
|
||||||
|
BEFORE INSERT ON {table}
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
IF ||':'||'NEW.id IS NULL THEN
|
||||||
|
SELECT {seq}.NEXTVAL INTO '||':'||'NEW.id FROM dual;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
@@ -227,3 +274,7 @@ def downgrade():
|
|||||||
op.drop_table('charges')
|
op.drop_table('charges')
|
||||||
op.drop_table('accounts')
|
op.drop_table('accounts')
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
for table, seq, trg in sequences_and_triggers:
|
||||||
|
op.execute(text(f"DROP TRIGGER {trg}"))
|
||||||
|
op.execute(text(f"DROP SEQUENCE {seq}"))
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# echo "Running DB migrations..."
|
# echo "Running DB migrations..."
|
||||||
flask db migrate -m "Migration on $(date)"
|
# flask db migrate -m "Migration on $(date)"
|
||||||
flask db upgrade
|
# flask db upgrade
|
||||||
|
|
||||||
echo "Starting Gunicorn server..."
|
echo "Starting Gunicorn server..."
|
||||||
exec gunicorn -w 4 -b 0.0.0.0:5000 wsgi:wsgi_app
|
exec gunicorn -w 4 -b 0.0.0.0:5000 wsgi:wsgi_app
|
||||||
|
|||||||
Reference in New Issue
Block a user