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):