mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-01 09:00:18 +01:00
Crud webhook amount (#474)
* get_standalone_payment selects only incoming tx
This commit is contained in:
parent
93e58f4c80
commit
32ea1106f9
2 changed files with 20 additions and 14 deletions
26
conv.py
26
conv.py
|
@ -1,12 +1,12 @@
|
||||||
## Python script to migrate an LNbits SQLite DB to Postgres
|
|
||||||
## All credits to @Fritz446 for the awesome work
|
|
||||||
|
|
||||||
## pip install psycopg2 OR psycopg2-binary
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
# Python script to migrate an LNbits SQLite DB to Postgres
|
||||||
|
# All credits to @Fritz446 for the awesome work
|
||||||
|
|
||||||
|
|
||||||
|
# pip install psycopg2 OR psycopg2-binary
|
||||||
|
|
||||||
|
|
||||||
# Change these values as needed
|
# Change these values as needed
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ def get_postgres_cursor():
|
||||||
def check_db_versions(sqdb):
|
def check_db_versions(sqdb):
|
||||||
sqlite = get_sqlite_cursor(sqdb)
|
sqlite = get_sqlite_cursor(sqdb)
|
||||||
dblite = dict(sqlite.execute("SELECT * FROM dbversions;").fetchall())
|
dblite = dict(sqlite.execute("SELECT * FROM dbversions;").fetchall())
|
||||||
del dblite["lnurlpos"] # wrongly added?
|
if "lnurlpos" in dblite:
|
||||||
|
del dblite["lnurlpos"]
|
||||||
sqlite.close()
|
sqlite.close()
|
||||||
|
|
||||||
postgres = get_postgres_cursor()
|
postgres = get_postgres_cursor()
|
||||||
|
@ -42,7 +43,7 @@ def check_db_versions(sqdb):
|
||||||
dbpost = dict(postgres.fetchall())
|
dbpost = dict(postgres.fetchall())
|
||||||
|
|
||||||
for key in dblite.keys():
|
for key in dblite.keys():
|
||||||
if dblite[key] != dbpost[key]:
|
if key in dblite and key in dbpost and dblite[key] != dbpost[key]:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"sqlite database version ({dblite[key]}) of {key} doesn't match postgres database version {dbpost[key]}"
|
f"sqlite database version ({dblite[key]}) of {key} doesn't match postgres database version {dbpost[key]}"
|
||||||
)
|
)
|
||||||
|
@ -76,7 +77,10 @@ def insert_to_pg(query, data):
|
||||||
connection = cursor.connection
|
connection = cursor.connection
|
||||||
|
|
||||||
for d in data:
|
for d in data:
|
||||||
cursor.execute(query, d)
|
try:
|
||||||
|
cursor.execute(query, d)
|
||||||
|
except:
|
||||||
|
raise ValueError(f"Failed to insert {d}")
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
|
@ -30,7 +30,8 @@ async def get_account(
|
||||||
user_id: str, conn: Optional[Connection] = None
|
user_id: str, conn: Optional[Connection] = None
|
||||||
) -> Optional[User]:
|
) -> Optional[User]:
|
||||||
row = await (conn or db).fetchone(
|
row = await (conn or db).fetchone(
|
||||||
"SELECT id, email, pass as password FROM accounts WHERE id = ?", (user_id,)
|
"SELECT id, email, pass as password FROM accounts WHERE id = ?", (
|
||||||
|
user_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return User(**row) if row else None
|
return User(**row) if row else None
|
||||||
|
@ -184,7 +185,7 @@ async def get_standalone_payment(
|
||||||
"""
|
"""
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM apipayments
|
FROM apipayments
|
||||||
WHERE checking_id = ? OR hash = ?
|
WHERE (checking_id = ? OR hash = ?) AND amount > 0 -- only the incoming payment
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
""",
|
""",
|
||||||
(checking_id_or_hash, checking_id_or_hash),
|
(checking_id_or_hash, checking_id_or_hash),
|
||||||
|
@ -304,7 +305,8 @@ async def delete_expired_invoices(conn: Optional[Connection] = None,) -> None:
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
expiration_date = datetime.datetime.fromtimestamp(
|
||||||
|
invoice.date + invoice.expiry)
|
||||||
if expiration_date > datetime.datetime.utcnow():
|
if expiration_date > datetime.datetime.utcnow():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue