diff --git a/lnbits/extensions/events/crud.py b/lnbits/extensions/events/crud.py index 6a9e9ab..733890a 100644 --- a/lnbits/extensions/events/crud.py +++ b/lnbits/extensions/events/crud.py @@ -13,7 +13,7 @@ def create_ticket(checking_id: str, wallet: str, event: str, name: str, email: with open_ext_db("events") as db: db.execute( """ - INSERT INTO tickets (id, paid, wallet, event, name, email, registered) + INSERT INTO ticket (id, paid, wallet, event, name, email, registered) VALUES (?, ?, ?, ?, ?, ?, ?) """, (checking_id, False, wallet, event, name, email, False), @@ -23,12 +23,12 @@ def create_ticket(checking_id: str, wallet: str, event: str, name: str, email: def update_ticket(paid: bool, checking_id: str) -> Tickets: with open_ext_db("events") 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 = ? """, @@ -51,7 +51,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets: def get_ticket(checking_id: str) -> Optional[Tickets]: with open_ext_db("events") as db: - row = db.fetchone("SELECT * FROM tickets WHERE id = ?", (checking_id,)) + row = db.fetchone("SELECT * FROM ticket WHERE id = ?", (checking_id,)) return Tickets(**row) if row else None @@ -62,14 +62,14 @@ def get_tickets(wallet_ids: Union[str, List[str]]) -> List[Tickets]: with open_ext_db("events") 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,)) print("scrum") return [Tickets(**row) for row in rows] def delete_ticket(checking_id: str) -> None: with open_ext_db("events") as db: - db.execute("DELETE FROM tickets WHERE id = ?", (checking_id,)) + db.execute("DELETE FROM ticket WHERE id = ?", (checking_id,)) @@ -127,16 +127,16 @@ def delete_event(event_id: str) -> None: def get_event_tickets(event_id: str, wallet_id: str) -> Tickets: with open_ext_db("events") as db: - rows = db.fetchall("SELECT * FROM tickets WHERE wallet = ? AND event = ?", (wallet_id, event_id)) + rows = db.fetchall("SELECT * FROM ticket WHERE wallet = ? AND event = ?", (wallet_id, event_id)) print(rows) return [Tickets(**row) for row in rows] def reg_ticket(ticket_id: str) -> Tickets: with open_ext_db("events") as db: - db.execute("UPDATE tickets SET registered = ? WHERE id = ?", (True, ticket_id)) - ticket = db.fetchone("SELECT * FROM tickets WHERE id = ?", (ticket_id,)) + db.execute("UPDATE ticket SET registered = ? WHERE id = ?", (True, ticket_id)) + ticket = db.fetchone("SELECT * FROM ticket WHERE id = ?", (ticket_id,)) print(ticket[2]) - rows = db.fetchall("SELECT * FROM tickets WHERE event = ?", (ticket[2],)) + rows = db.fetchall("SELECT * FROM ticket WHERE event = ?", (ticket[2],)) return [Tickets(**row) for row in rows] \ No newline at end of file diff --git a/lnbits/extensions/events/migrations.py b/lnbits/extensions/events/migrations.py index 4d8a189..ad6cae3 100644 --- a/lnbits/extensions/events/migrations.py +++ b/lnbits/extensions/events/migrations.py @@ -35,7 +35,60 @@ def m001_initial(db): """ ) + +def m002_changed(db): + + db.execute( + """ + CREATE TABLE IF NOT EXISTS ticket ( + id TEXT PRIMARY KEY, + paid BOOLEAN NOT NULL, + wallet TEXT NOT NULL, + event TEXT NOT NULL, + name TEXT NOT NULL, + email TEXT NOT NULL, + registered BOOLEAN 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, + wallet, + event, + name, + email, + registered + ) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + ( + row[0], + True, + row[1], + row[2], + row[3], + row[4], + row[5], + ), + ) + db.execute("DROP TABLE tickets") + def migrate(): with open_ext_db("events") as db: m001_initial(db) + m002_changed(db)