mint: reenable balance views (#190)

This commit is contained in:
calle
2023-05-02 00:52:26 +02:00
committed by GitHub
parent 61078ce7c8
commit 84d2471902

View File

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