Fixed lntickets migration

This commit is contained in:
arcbtc 2020-08-13 21:49:50 +01:00
parent dfdb890751
commit 2d580a0d0e
2 changed files with 67 additions and 7 deletions

View File

@ -14,7 +14,7 @@ def create_ticket(checking_id: str, wallet: str, form: str, name: str, email:
with open_ext_db("lnticket") as db:
db.execute(
"""
INSERT INTO tickets (id, paid, form, email, ltext, name, wallet, sats)
INSERT INTO ticket (id, paid, form, email, ltext, name, wallet, sats)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(checking_id, False, form, email, ltext, name, wallet, sats),
@ -24,12 +24,12 @@ def create_ticket(checking_id: str, wallet: str, form: str, name: str, email:
def update_ticket(paid: bool, checking_id: str) -> Tickets:
with open_ext_db("lnticket") as db:
row = db.fetchone("SELECT * FROM tickets WHERE id = ?", (checking_id,))
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (checking_id,))
if row[1] == True:
return get_ticket(checking_id)
db.execute(
"""
UPDATE tickets
UPDATE ticket
SET paid = ?
WHERE id = ?
""",
@ -50,7 +50,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
def get_ticket(ticket_id: str) -> Optional[Tickets]:
with open_ext_db("lnticket") as db:
row = db.fetchone("SELECT * FROM tickets WHERE id = ?", (ticket_id,))
row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (ticket_id,))
return Tickets(**row) if row else None
@ -61,14 +61,14 @@ def get_tickets(wallet_ids: Union[str, List[str]]) -> List[Tickets]:
with open_ext_db("lnticket") as db:
q = ",".join(["?"] * len(wallet_ids))
rows = db.fetchall(f"SELECT * FROM tickets WHERE wallet IN ({q})", (*wallet_ids,))
rows = db.fetchall(f"SELECT * FROM ticket WHERE wallet IN ({q})", (*wallet_ids,))
return [Tickets(**row) for row in rows]
def delete_ticket(ticket_id: str) -> None:
with open_ext_db("lnticket") as db:
db.execute("DELETE FROM tickets WHERE id = ?", (ticket_id,))
db.execute("DELETE FROM ticket WHERE id = ?", (ticket_id,))

View File

@ -32,6 +32,66 @@ def m001_initial(db):
"""
)
def m002_changed(db):
db.execute(
"""
CREATE TABLE IF NOT EXISTS ticket (
id TEXT PRIMARY KEY,
paid BOOLEAN NOT NULL,
form TEXT NOT NULL,
email TEXT NOT NULL,
ltext TEXT NOT NULL,
name TEXT NOT NULL,
wallet TEXT NOT NULL,
sats INTEGER NOT NULL,
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
);
"""
)
for row in [list(row) for row in db.fetchall("SELECT * FROM tickets")]:
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 ticket (
id,
paid,
title,
form,
email,
ltext,
name,
wallet,
sats
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
row[0],
True,
row[1],
row[2],
row[3],
row[4],
row[5],
row[6],
row[7],
row[8],
),
)
db.execute("DROP TABLE tickets")
def migrate():
with open_ext_db("lnticket") as db:
m001_initial(db)
m001_initial(db)
m002_changed(db)