Add models and migrations

This commit is contained in:
Fitti 2021-06-22 13:18:50 +02:00
parent 2dded1b585
commit c759f3617e
2 changed files with 55 additions and 13 deletions

View file

@ -2,10 +2,31 @@ async def m001_initial(db):
await db.execute(
"""
CREATE TABLE IF NOT EXISTS TwitchAlerts (
id TEXT PRIMARY KEY,
CREATE TABLE IF NOT EXISTS Services (
id INTEGER PRIMARY KEY AUTOINCREMENT,
twitchuser TEXT NOT NULL,
client_id TEXT NOT NULL,
client_secret TEXT NOT NULL,
wallet TEXT NOT NULL,
time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now'))
onchain TEXT,
servicename TEXT NOT NULL,
authenticated BOOLEAN NOT NULL,
token TEXT
);
"""
"""
)
await db.execute(
"""
CREATE TABLE IF NOT EXISTS Donations (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
cur_code TEXT NOT NULL,
sats INT NOT NULL,
amount FLOAT NOT NULL,
service INTEGER NOT NULL,
posted BOOLEAN NOT NULL,
FOREIGN KEY(service) REFERENCES Services(id)
);
"""
)

View file

@ -1,11 +1,32 @@
# from sqlite3 import Row
# from typing import NamedTuple
from sqlite3 import Row
from typing import NamedTuple, Optional
# class Example(NamedTuple):
# id: str
# wallet: str
#
# @classmethod
# def from_row(cls, row: Row) -> "Example":
# return cls(**dict(row))
class Donations(NamedTuple):
id: str
name: str
cur_code: str
sats: int
amount: float
service: int
posted: bool
@classmethod
def from_row(cls, row: Row) -> "Donations":
return cls(**dict(row))
class Services(NamedTuple):
id: int
twitchuser: str
client_id: str
client_secret: str
wallet: str
onchain: str
servicename: str
authenticated: bool
token: Optional[int]
@classmethod
def from_row(cls, row: Row) -> "Services":
return cls(**dict(row))