clean migration

This commit is contained in:
callebtc 2022-12-06 13:23:51 +01:00
parent 07724eaa0f
commit 36cebffbf5

View file

@ -197,13 +197,14 @@ async def m005_balance_check_balance_notify(db):
async def m006_add_invoice_expiry_to_apipayments(db): async def m006_add_invoice_expiry_to_apipayments(db):
""" """
Adds invoice expiry field to apipayments and precomputes them for Adds invoice expiry column to apipayments and precomputes them for
existing entries existing entries
""" """
try: try:
await db.execute("ALTER TABLE apipayments ADD COLUMN expiry TIMESTAMP") await db.execute("ALTER TABLE apipayments ADD COLUMN expiry TIMESTAMP")
except OperationalError: except OperationalError:
pass pass
try: try:
rows = await ( rows = await (
await db.execute( await db.execute(
@ -217,12 +218,11 @@ async def m006_add_invoice_expiry_to_apipayments(db):
""" """
) )
).fetchall() ).fetchall()
logger.info(f"Checking expiry of {len(rows)} invoices") logger.info(f"Mirgraion: Checking expiry of {len(rows)} invoices")
for i, ( for i, (
payment_request, payment_request,
checking_id, checking_id,
) in enumerate(rows): ) in enumerate(rows):
logger.info(f"Checking invoice {i}/{len(rows)}")
try: try:
invoice = bolt11.decode(payment_request) invoice = bolt11.decode(payment_request)
if invoice.expiry is None: if invoice.expiry is None:
@ -232,7 +232,7 @@ async def m006_add_invoice_expiry_to_apipayments(db):
invoice.date + invoice.expiry invoice.date + invoice.expiry
) )
logger.info( logger.info(
f"Setting expiry of invoice {invoice.payment_hash} to {expiration_date}" f"Mirgraion: {i}/{len(rows)} setting expiry of invoice {invoice.payment_hash} to {expiration_date}"
) )
await db.execute( await db.execute(
""" """