Skip to content

Commit bec976b

Browse files
DB migration
1 parent 53a31cb commit bec976b

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""add credit transaction classification enums
2+
3+
Revision ID: a3a58471b0f1
4+
Revises: 307017ee1a49
5+
Create Date: 2025-01-14 13:44:05.025647+00:00
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
11+
# revision identifiers, used by Alembic.
12+
revision = "a3a58471b0f1"
13+
down_revision = "307017ee1a49"
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
op.execute(sa.DDL("ALTER TYPE credittransactionstatus ADD VALUE 'IN_DEBT'"))
20+
op.execute(
21+
sa.DDL(
22+
"ALTER TYPE credittransactionclassification ADD VALUE 'ADD_WALLET_EXCHANGE'"
23+
)
24+
)
25+
op.execute(
26+
sa.DDL(
27+
"ALTER TYPE credittransactionclassification ADD VALUE 'DEDUCT_WALLET_EXCHANGE'"
28+
)
29+
)
30+
31+
32+
def downgrade():
33+
# ### commands auto generated by Alembic - please adjust! ###
34+
pass
35+
# ### end Alembic commands ###

services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/credit_transactions_db.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,28 @@ async def batch_update_credit_transaction_status_for_in_debt_transactions(
141141
wallet_id: WalletID,
142142
transaction_status: CreditTransactionStatus,
143143
) -> None:
144-
async with transaction_context(engine, connection) as conn:
145-
update_stmt = (
146-
resource_tracker_credit_transactions.update()
147-
.values(
148-
modified=sa.func.now(),
149-
transaction_status=transaction_status,
150-
)
151-
.where(
152-
(resource_tracker_credit_transactions.c.wallet_id == f"{wallet_id}")
153-
& (
154-
resource_tracker_credit_transactions.c.transaction_status
155-
== CreditTransactionStatus.IN_DEBT
156-
)
157-
)
144+
update_stmt = (
145+
resource_tracker_credit_transactions.update()
146+
.values(
147+
modified=sa.func.now(),
148+
transaction_status=transaction_status,
158149
)
159-
160-
if project_id:
161-
update_stmt = update_stmt.where(
162-
resource_tracker_credit_transactions.c.project_id == f"{project_id}"
150+
.where(
151+
(resource_tracker_credit_transactions.c.wallet_id == wallet_id)
152+
& (
153+
resource_tracker_credit_transactions.c.transaction_status
154+
== CreditTransactionStatus.IN_DEBT
163155
)
156+
)
157+
)
164158

165-
await conn.execute(update_stmt)
159+
if project_id:
160+
update_stmt = update_stmt.where(
161+
resource_tracker_credit_transactions.c.project_id == f"{project_id}"
162+
)
163+
async with transaction_context(engine, connection) as conn:
164+
result = await conn.execute(update_stmt)
165+
print(result)
166166

167167

168168
async def sum_credit_transactions_by_product_and_wallet(

0 commit comments

Comments
 (0)