Skip to content

Commit

Permalink
DB migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Jan 14, 2025
1 parent 53a31cb commit bec976b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""add credit transaction classification enums
Revision ID: a3a58471b0f1
Revises: 307017ee1a49
Create Date: 2025-01-14 13:44:05.025647+00:00
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "a3a58471b0f1"
down_revision = "307017ee1a49"
branch_labels = None
depends_on = None


def upgrade():
op.execute(sa.DDL("ALTER TYPE credittransactionstatus ADD VALUE 'IN_DEBT'"))
op.execute(
sa.DDL(
"ALTER TYPE credittransactionclassification ADD VALUE 'ADD_WALLET_EXCHANGE'"
)
)
op.execute(
sa.DDL(
"ALTER TYPE credittransactionclassification ADD VALUE 'DEDUCT_WALLET_EXCHANGE'"
)
)


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,28 @@ async def batch_update_credit_transaction_status_for_in_debt_transactions(
wallet_id: WalletID,
transaction_status: CreditTransactionStatus,
) -> None:
async with transaction_context(engine, connection) as conn:
update_stmt = (
resource_tracker_credit_transactions.update()
.values(
modified=sa.func.now(),
transaction_status=transaction_status,
)
.where(
(resource_tracker_credit_transactions.c.wallet_id == f"{wallet_id}")
& (
resource_tracker_credit_transactions.c.transaction_status
== CreditTransactionStatus.IN_DEBT
)
)
update_stmt = (
resource_tracker_credit_transactions.update()
.values(
modified=sa.func.now(),
transaction_status=transaction_status,
)

if project_id:
update_stmt = update_stmt.where(
resource_tracker_credit_transactions.c.project_id == f"{project_id}"
.where(
(resource_tracker_credit_transactions.c.wallet_id == wallet_id)
& (
resource_tracker_credit_transactions.c.transaction_status
== CreditTransactionStatus.IN_DEBT
)
)
)

await conn.execute(update_stmt)
if project_id:
update_stmt = update_stmt.where(
resource_tracker_credit_transactions.c.project_id == f"{project_id}"
)
async with transaction_context(engine, connection) as conn:
result = await conn.execute(update_stmt)
print(result)


async def sum_credit_transactions_by_product_and_wallet(
Expand Down

0 comments on commit bec976b

Please sign in to comment.