Fixed LNURLw migration
This commit is contained in:
parent
c73fbe1b27
commit
c17ac32c86
2 changed files with 83 additions and 7 deletions
|
|
@ -24,7 +24,7 @@ def create_withdraw_link(
|
||||||
link_id = urlsafe_short_hash()
|
link_id = urlsafe_short_hash()
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO withdraw_links (
|
INSERT INTO withdraw_link (
|
||||||
id,
|
id,
|
||||||
wallet,
|
wallet,
|
||||||
title,
|
title,
|
||||||
|
|
@ -60,7 +60,7 @@ def create_withdraw_link(
|
||||||
|
|
||||||
def get_withdraw_link(link_id: str, num=None) -> Optional[WithdrawLink]:
|
def get_withdraw_link(link_id: str, num=None) -> Optional[WithdrawLink]:
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
row = db.fetchone("SELECT * FROM withdraw_links WHERE id = ?", (link_id,))
|
row = db.fetchone("SELECT * FROM withdraw_link WHERE id = ?", (link_id,))
|
||||||
link = []
|
link = []
|
||||||
for item in row:
|
for item in row:
|
||||||
link.append(item)
|
link.append(item)
|
||||||
|
|
@ -71,7 +71,7 @@ def get_withdraw_link(link_id: str, num=None) -> Optional[WithdrawLink]:
|
||||||
|
|
||||||
def get_withdraw_link_by_hash(unique_hash: str, num=None) -> Optional[WithdrawLink]:
|
def get_withdraw_link_by_hash(unique_hash: str, num=None) -> Optional[WithdrawLink]:
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
row = db.fetchone("SELECT * FROM withdraw_links WHERE unique_hash = ?", (unique_hash,))
|
row = db.fetchone("SELECT * FROM withdraw_link WHERE unique_hash = ?", (unique_hash,))
|
||||||
link = []
|
link = []
|
||||||
for item in row:
|
for item in row:
|
||||||
link.append(item)
|
link.append(item)
|
||||||
|
|
@ -90,7 +90,7 @@ def get_withdraw_links(wallet_ids: Union[str, List[str]]) -> List[WithdrawLink]:
|
||||||
|
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
q = ",".join(["?"] * len(wallet_ids))
|
q = ",".join(["?"] * len(wallet_ids))
|
||||||
rows = db.fetchall(f"SELECT * FROM withdraw_links WHERE wallet IN ({q})", (*wallet_ids,))
|
rows = db.fetchall(f"SELECT * FROM withdraw_link WHERE wallet IN ({q})", (*wallet_ids,))
|
||||||
|
|
||||||
return [WithdrawLink.from_row(row) for row in rows]
|
return [WithdrawLink.from_row(row) for row in rows]
|
||||||
|
|
||||||
|
|
@ -98,15 +98,15 @@ def get_withdraw_links(wallet_ids: Union[str, List[str]]) -> List[WithdrawLink]:
|
||||||
def update_withdraw_link(link_id: str, **kwargs) -> Optional[WithdrawLink]:
|
def update_withdraw_link(link_id: str, **kwargs) -> Optional[WithdrawLink]:
|
||||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
db.execute(f"UPDATE withdraw_links SET {q} WHERE id = ?", (*kwargs.values(), link_id))
|
db.execute(f"UPDATE withdraw_link SET {q} WHERE id = ?", (*kwargs.values(), link_id))
|
||||||
row = db.fetchone("SELECT * FROM withdraw_links WHERE id = ?", (link_id,))
|
row = db.fetchone("SELECT * FROM withdraw_link WHERE id = ?", (link_id,))
|
||||||
|
|
||||||
return WithdrawLink.from_row(row) if row else None
|
return WithdrawLink.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
def delete_withdraw_link(link_id: str) -> None:
|
def delete_withdraw_link(link_id: str) -> None:
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
db.execute("DELETE FROM withdraw_links WHERE id = ?", (link_id,))
|
db.execute("DELETE FROM withdraw_link WHERE id = ?", (link_id,))
|
||||||
|
|
||||||
def chunks(lst, n):
|
def chunks(lst, n):
|
||||||
for i in range(0, len(lst), n):
|
for i in range(0, len(lst), n):
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,84 @@ def m001_initial(db):
|
||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
def m002_change_withdraw_table(db):
|
||||||
|
"""
|
||||||
|
Creates an improved withdraw table and migrates the existing data.
|
||||||
|
"""
|
||||||
|
db.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS withdraw_link (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
wallet TEXT,
|
||||||
|
title TEXT,
|
||||||
|
min_withdrawable INTEGER DEFAULT 1,
|
||||||
|
max_withdrawable INTEGER DEFAULT 1,
|
||||||
|
uses INTEGER DEFAULT 1,
|
||||||
|
wait_time INTEGER,
|
||||||
|
is_unique INTEGER DEFAULT 0,
|
||||||
|
unique_hash TEXT UNIQUE,
|
||||||
|
k1 TEXT,
|
||||||
|
open_time INTEGER,
|
||||||
|
used INTEGER DEFAULT 0,
|
||||||
|
usescsv TEXT
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
db.execute("CREATE INDEX IF NOT EXISTS wallet_idx ON withdraw_link (wallet)")
|
||||||
|
db.execute("CREATE UNIQUE INDEX IF NOT EXISTS unique_hash_idx ON withdraw_link (unique_hash)")
|
||||||
|
|
||||||
|
for row in [list(row) for row in db.fetchall("SELECT * FROM withdraw_links")]:
|
||||||
|
usescsv = ""
|
||||||
|
|
||||||
|
for i in range(row[5]):
|
||||||
|
if row[7]:
|
||||||
|
usescsv += "," + str(i + 1)
|
||||||
|
else:
|
||||||
|
usescsv += "," + str(1)
|
||||||
|
usescsv = usescsv[1:]
|
||||||
|
db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO withdraw_link (
|
||||||
|
id,
|
||||||
|
wallet,
|
||||||
|
title,
|
||||||
|
min_withdrawable,
|
||||||
|
max_withdrawable,
|
||||||
|
uses,
|
||||||
|
wait_time,
|
||||||
|
is_unique,
|
||||||
|
unique_hash,
|
||||||
|
k1,
|
||||||
|
open_time,
|
||||||
|
used,
|
||||||
|
usescsv
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
row[0],
|
||||||
|
row[1],
|
||||||
|
row[2],
|
||||||
|
row[3],
|
||||||
|
row[4],
|
||||||
|
row[5],
|
||||||
|
row[6],
|
||||||
|
row[7],
|
||||||
|
row[8],
|
||||||
|
row[9],
|
||||||
|
row[10],
|
||||||
|
row[11],
|
||||||
|
usescsv,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
db.execute("DROP TABLE withdraw_links")
|
||||||
|
|
||||||
def migrate():
|
def migrate():
|
||||||
with open_ext_db("withdraw") as db:
|
with open_ext_db("withdraw") as db:
|
||||||
m001_initial(db)
|
m001_initial(db)
|
||||||
|
m002_change_withdraw_table(db)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue