From 84d24719023202caf0a0e1fec6317bd7a31c1b30 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Tue, 2 May 2023 00:52:26 +0200 Subject: [PATCH] mint: reenable balance views (#190) --- cashu/mint/migrations.py | 60 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index 7380780..d407673 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -54,38 +54,38 @@ async def m001_initial(db: Database): """ ) - # await db.execute( - # f""" - # CREATE VIEW {table_with_schema(db, 'balance_issued')} AS - # SELECT COALESCE(SUM(s), 0) AS balance FROM ( - # SELECT SUM(amount) AS s - # FROM {table_with_schema(db, 'promises')} - # WHERE amount > 0 - # ); - # """ - # ) + await db.execute( + f""" + CREATE VIEW {table_with_schema(db, 'balance_issued')} AS + SELECT COALESCE(SUM(s), 0) AS balance FROM ( + SELECT SUM(amount) AS s + FROM {table_with_schema(db, 'promises')} + WHERE amount > 0 + ); + """ + ) - # await db.execute( - # f""" - # CREATE VIEW {table_with_schema(db, 'balance_used')} AS - # SELECT COALESCE(SUM(s), 0) AS balance FROM ( - # SELECT SUM(amount) AS s - # FROM {table_with_schema(db, 'proofs_used')} - # WHERE amount > 0 - # ); - # """ - # ) + await db.execute( + f""" + CREATE VIEW {table_with_schema(db, 'balance_redeemed')} AS + SELECT COALESCE(SUM(s), 0) AS balance FROM ( + SELECT SUM(amount) AS s + FROM {table_with_schema(db, 'proofs_used')} + WHERE amount > 0 + ); + """ + ) - # await db.execute( - # f""" - # CREATE VIEW {table_with_schema(db, 'balance')} AS - # SELECT s_issued - s_used AS balance FROM ( - # SELECT bi.balance AS s_issued, bu.balance AS s_used - # FROM {table_with_schema(db, 'balance_issued')} bi - # CROSS JOIN {table_with_schema(db, 'balance_used')} bu - # ); - # """ - # ) + await db.execute( + f""" + CREATE VIEW {table_with_schema(db, 'balance')} AS + SELECT s_issued - s_used AS balance FROM ( + SELECT bi.balance AS s_issued, bu.balance AS s_used + FROM {table_with_schema(db, 'balance_issued')} bi + CROSS JOIN {table_with_schema(db, 'balance_redeemed')} bu + ); + """ + ) async def m003_mint_keysets(db: Database):