From 96b07af3319ebfea6c1aa45411828371222fd9da Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 5 Jan 2023 22:20:10 +0000 Subject: [PATCH] swapped timestamp type for float, fixes issue --- lnbits/extensions/gerty/crud.py | 2 +- lnbits/extensions/gerty/migrations.py | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index 54ce8e1b..24e8ef25 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -122,7 +122,7 @@ async def get_mempool_info(endPoint: str, gerty) -> dict: ), ) return response.json() - if int(time.time()) - int(row.time) > 20: + if float(time.time()) - row.time > 20: async with httpx.AsyncClient() as client: response = await client.get(gerty.mempool_endpoint + url) await db.execute( diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index 654dfcbf..31d1caec 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -1,3 +1,5 @@ +import time + async def m001_initial(db): """ Initial Gertys table. @@ -57,3 +59,52 @@ async def m005_add_gerty_model_col(db): support for Gerty model col """ await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;") + +async def m006_add_gerty_model_col(db): + """ + support for Gerty model col + """ + await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old;") + await db.execute("ALTER TABLE gerty.mempool ADD COLUMN time FLOAT;") + +async def m006_add_gerty_model_col(db): + """ + Add UUID ID's to links and migrates existing data + """ + await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old") + await db.execute( + f""" + CREATE TABLE gerty.mempool ( + id TEXT PRIMARY KEY, + mempool_endpoint TEXT NOT NULL, + endpoint TEXT NOT NULL, + data TEXT NOT NULL, + time FLOAT + ); + """ + ) + + for row in [ + list(row) for row in await db.fetchall("SELECT * FROM gerty.mempool_old") + ]: + await db.execute( + """ + INSERT INTO gerty.mempool ( + id, + mempool_endpoint, + endpoint, + data, + time + ) + VALUES (?, ?, ?, ?, ?) + """, + ( + row[0], + row[1], + row[2], + row[3], + time.time(), + ), + ) + + await db.execute("DROP TABLE gerty.mempool_old") \ No newline at end of file