Fixed migration bug

This commit is contained in:
arcbtc 2020-08-13 23:43:42 +01:00
parent 3c7e4a3eaf
commit dd2a282158
6 changed files with 26 additions and 30 deletions

View File

@ -13,10 +13,10 @@ def create_ticket(checking_id: str, wallet: str, event: str, name: str, email:
with open_ext_db("events") as db:
db.execute(
"""
INSERT INTO ticket (id, paid, wallet, event, name, email, registered)
INSERT INTO ticket (id, wallet, event, name, email, registered, paid)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(checking_id, False, wallet, event, name, email, False),
(checking_id, wallet, event, name, email, False, False),
)
return get_ticket(checking_id)
@ -24,7 +24,7 @@ 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 ticket WHERE id = ?", (checking_id,))
if row[1] == True:
if row[6] == True:
return get_ticket(checking_id)
db.execute(
"""
@ -35,7 +35,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
(paid, checking_id),
)
eventdata = get_event(row[3])
eventdata = get_event(row[2])
sold = eventdata.sold + 1
amount_tickets = eventdata.amount_tickets - 1
db.execute(
@ -44,7 +44,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
SET sold = ?, amount_tickets = ?
WHERE id = ?
""",
(sold, amount_tickets, row[3]),
(sold, amount_tickets, row[2]),
)
return get_ticket(checking_id)
@ -136,7 +136,7 @@ def reg_ticket(ticket_id: str) -> Tickets:
with open_ext_db("events") as db:
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 ticket WHERE event = ?", (ticket[2],))
print(ticket[1])
rows = db.fetchall("SELECT * FROM ticket WHERE event = ?", (ticket[1],))
return [Tickets(**row) for row in rows]

View File

@ -24,7 +24,6 @@ def m001_initial(db):
"""
CREATE TABLE IF NOT EXISTS tickets (
id TEXT PRIMARY KEY,
paid BOOLEAN NOT NULL,
wallet TEXT NOT NULL,
event TEXT NOT NULL,
name TEXT NOT NULL,
@ -42,12 +41,12 @@ def m002_changed(db):
"""
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,
paid BOOLEAN NOT NULL,
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
);
"""
@ -66,23 +65,23 @@ def m002_changed(db):
"""
INSERT INTO ticket (
id,
paid,
wallet,
event,
name,
email,
registered
registered,
paid
)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(
row[0],
True,
row[1],
row[2],
row[3],
row[4],
row[5],
True,
),
)
db.execute("DROP TABLE tickets")

View File

@ -16,10 +16,10 @@ class Events(NamedTuple):
class Tickets(NamedTuple):
id: str
paid: bool
wallet: str
event: str
name: str
email: str
registered: bool
paid: bool
time: int

View File

@ -14,10 +14,10 @@ def create_ticket(checking_id: str, wallet: str, form: str, name: str, email:
with open_ext_db("lnticket") as db:
db.execute(
"""
INSERT INTO ticket (id, paid, form, email, ltext, name, wallet, sats)
INSERT INTO ticket (id, form, email, ltext, name, wallet, sats, paid)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(checking_id, False, form, email, ltext, name, wallet, sats),
(checking_id, form, email, ltext, name, wallet, sats, False),
)
return get_ticket(checking_id)
@ -25,7 +25,7 @@ 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 ticket WHERE id = ?", (checking_id,))
if row[1] == True:
if row[7] == True:
return get_ticket(checking_id)
db.execute(
"""
@ -36,7 +36,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
(paid, checking_id),
)
formdata = get_form(row[2])
formdata = get_form(row[1])
amount = formdata.amountmade + row[7]
db.execute(
"""
@ -44,7 +44,7 @@ def update_ticket(paid: bool, checking_id: str) -> Tickets:
SET amountmade = ?
WHERE id = ?
""",
(amount, row[2]),
(amount, row[1]),
)
return get_ticket(checking_id)

View File

@ -20,7 +20,6 @@ def m001_initial(db):
"""
CREATE TABLE IF NOT EXISTS tickets (
id TEXT PRIMARY KEY,
paid BOOLEAN NOT NULL,
form TEXT NOT NULL,
email TEXT NOT NULL,
ltext TEXT NOT NULL,
@ -39,18 +38,19 @@ def m002_changed(db):
"""
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,
paid 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 = ""
@ -64,28 +64,25 @@ def m002_changed(db):
"""
INSERT INTO ticket (
id,
paid,
title,
form,
email,
ltext,
name,
wallet,
sats
sats,
paid
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(
row[0],
True,
row[0],
row[1],
row[2],
row[3],
row[4],
row[5],
row[6],
row[7],
row[8],
True,
),
)
db.execute("DROP TABLE tickets")

View File

@ -13,12 +13,12 @@ class Forms(NamedTuple):
class Tickets(NamedTuple):
id: str
paid: bool
form: str
email: str
ltext: str
name: str
wallet: str
sats: int
paid: bool
time: int