From bec976b77307f64822abea5a875fc88a96218908 Mon Sep 17 00:00:00 2001 From: matusdrobuliak66 Date: Tue, 14 Jan 2025 15:37:13 +0100 Subject: [PATCH] DB migration --- ..._add_credit_transaction_classification_.py | 35 +++++++++++++++++ .../modules/db/credit_transactions_db.py | 38 +++++++++---------- 2 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 packages/postgres-database/src/simcore_postgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.py diff --git a/packages/postgres-database/src/simcore_postgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.py b/packages/postgres-database/src/simcore_postgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.py new file mode 100644 index 00000000000..9bdd1c6ee2d --- /dev/null +++ b/packages/postgres-database/src/simcore_postgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.py @@ -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 ### diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/credit_transactions_db.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/credit_transactions_db.py index ec3f5510182..3c52c2f72da 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/credit_transactions_db.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/credit_transactions_db.py @@ -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(