Skip to content

Commit 55dceb4

Browse files
amalcaraznesitor
authored andcommitted
fix: fixed price / ratio migration & include credit bonus_amount in response
1 parent 67dc561 commit 55dceb4

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

deployment/migrations/versions/0040_e1f2a3b4c5d6_rename_credit_history_ratio_to_price.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def upgrade() -> None:
2424
op.add_column('credit_history', sa.Column('bonus_amount', sa.BigInteger(), nullable=True))
2525

2626
# Transform data: price calculation depends on payment token
27-
# For ALEPH token: price = 1 / (ratio * 0.8)
27+
# For ALEPH token: ratio = (1 / price) * (1 + 0.2), therefore price = 1.2 / ratio
2828
# For other tokens: price = 1/ratio
2929
# Only update rows where payment_method is NOT 'credit_expense' or 'credit_transfer'
3030
# and where ratio is not null and not zero
3131
connection = op.get_bind()
3232
connection.execute(sa.text("""
3333
UPDATE credit_history
3434
SET price = CASE
35-
WHEN token = 'ALEPH' THEN ROUND(1.0 / (ratio * 0.8), 18)
35+
WHEN token = 'ALEPH' THEN ROUND(1.2 / ratio, 18)
3636
ELSE ROUND(1.0 / ratio, 18)
3737
END
3838
WHERE ratio IS NOT NULL
@@ -58,13 +58,13 @@ def downgrade() -> None:
5858
op.add_column('credit_history', sa.Column('ratio', sa.DECIMAL(), nullable=True))
5959

6060
# Transform data back: reverse price calculation depends on payment token
61-
# For ALEPH token: ratio = (1/price) / 0.8
61+
# For ALEPH token: price = 1.2 / ratio, therefore ratio = 1.2 / price
6262
# For other tokens: ratio = 1/price
6363
connection = op.get_bind()
6464
connection.execute(sa.text("""
6565
UPDATE credit_history
6666
SET ratio = CASE
67-
WHEN token = 'ALEPH' THEN ROUND((1.0 / price) / 0.8, 18)
67+
WHEN token = 'ALEPH' THEN ROUND(1.2 / price, 18)
6868
ELSE ROUND(1.0 / price, 18)
6969
END
7070
WHERE price IS NOT NULL

src/aleph/schemas/api/accounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CreditHistoryResponseItem(BaseModel):
143143

144144
amount: int
145145
price: Optional[Decimal] = None
146+
bonus_amount: Optional[int] = None
146147
tx_hash: Optional[str] = None
147148
token: Optional[str] = None
148149
chain: Optional[str] = None

src/aleph/web/controllers/accounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ async def get_account_credit_history(request: web.Request) -> web.Response:
270270
{
271271
"amount": entry.amount,
272272
"price": entry.price,
273+
"bonus_amount": entry.bonus_amount,
273274
"tx_hash": entry.tx_hash,
274275
"token": entry.token,
275276
"chain": entry.chain,

0 commit comments

Comments
 (0)