From 74c9317277e0e4455eb8c4b24f015ab33be625c6 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 3 Dec 2023 00:02:05 +0100 Subject: [PATCH] mint: fix postgres migrations (#375) --- cashu/mint/migrations.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index 52c084f..54a109b 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -55,7 +55,7 @@ async def m002_add_balance_views(db: Database): SELECT SUM(amount) AS s FROM {table_with_schema(db, 'promises')} WHERE amount > 0 - ); + ) AS balance_issued; """) await conn.execute(f""" @@ -64,7 +64,7 @@ async def m002_add_balance_views(db: Database): SELECT SUM(amount) AS s FROM {table_with_schema(db, 'proofs_used')} WHERE amount > 0 - ); + ) AS balance_redeemed; """) await conn.execute(f""" @@ -183,9 +183,13 @@ async def m009_add_out_to_invoices(db: Database): # column in invoices for marking whether the invoice is incoming (out=False) or outgoing (out=True) async with db.connect() as conn: # we have to drop the balance views first and recreate them later - await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance')}") - await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_issued')}") - await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_redeemed')}") + await conn.execute(f"DROP VIEW IF EXISTS {table_with_schema(db, 'balance')}") + await conn.execute( + f"DROP VIEW IF EXISTS {table_with_schema(db, 'balance_issued')}" + ) + await conn.execute( + f"DROP VIEW IF EXISTS {table_with_schema(db, 'balance_redeemed')}" + ) # rename column pr to bolt11 await conn.execute( @@ -211,6 +215,6 @@ async def m010_add_index_to_proofs_used(db: Database): async with db.connect() as conn: await conn.execute( "CREATE INDEX IF NOT EXISTS" - f" {table_with_schema(db, 'proofs_used')}_secret_idx ON" + " proofs_used_secret_idx ON" f" {table_with_schema(db, 'proofs_used')} (secret)" )