From c759f3617e9e9441cb4fa76d56a924432d352de0 Mon Sep 17 00:00:00 2001 From: Fitti Date: Tue, 22 Jun 2021 13:18:50 +0200 Subject: [PATCH] Add models and migrations --- lnbits/extensions/TwitchAlerts/migrations.py | 29 +++++++++++++-- lnbits/extensions/TwitchAlerts/models.py | 39 +++++++++++++++----- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/lnbits/extensions/TwitchAlerts/migrations.py b/lnbits/extensions/TwitchAlerts/migrations.py index db0a9c7cb..39d7f0ae6 100644 --- a/lnbits/extensions/TwitchAlerts/migrations.py +++ b/lnbits/extensions/TwitchAlerts/migrations.py @@ -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) + ); + """ ) diff --git a/lnbits/extensions/TwitchAlerts/models.py b/lnbits/extensions/TwitchAlerts/models.py index be5232339..ce601d5aa 100644 --- a/lnbits/extensions/TwitchAlerts/models.py +++ b/lnbits/extensions/TwitchAlerts/models.py @@ -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))