Initial framework
This commit is contained in:
133
src/datamodels.py
Normal file
133
src/datamodels.py
Normal file
@@ -0,0 +1,133 @@
|
||||
from data import Registry, RowModel, Table
|
||||
from data.columns import String, Timestamp, Integer, Bool
|
||||
|
||||
|
||||
class UserAuth(RowModel):
|
||||
"""
|
||||
Schema
|
||||
======
|
||||
CREATE TABLE user_auth(
|
||||
userid TEXT PRIMARY KEY,
|
||||
token TEXT NOT NULL,
|
||||
refresh_token TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'user_auth'
|
||||
_cache_ = {}
|
||||
|
||||
userid = String(primary=True)
|
||||
token = String()
|
||||
refresh_token = String()
|
||||
created_at = Timestamp()
|
||||
_timestamp = Timestamp()
|
||||
|
||||
|
||||
class BotChannel(RowModel):
|
||||
"""
|
||||
Schema
|
||||
======
|
||||
CREATE TABLE bot_channels(
|
||||
userid TEXT PRIMARY KEY REFERENCES user_auth(userid) ON DELETE CASCADE,
|
||||
autojoin BOOLEAN DEFAULT true,
|
||||
listen_redeems BOOLEAN,
|
||||
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'bot_channels'
|
||||
_cache_ = {}
|
||||
|
||||
userid = String(primary=True)
|
||||
autojoin = Bool()
|
||||
listen_redeems = Bool()
|
||||
joined_at = Timestamp()
|
||||
_timestamp = Timestamp()
|
||||
|
||||
|
||||
class UserProfile(RowModel):
|
||||
"""
|
||||
Schema
|
||||
======
|
||||
CREATE TABLE user_profiles(
|
||||
profileid INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
twitchid TEXT NOT NULL,
|
||||
name TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'user_profiles'
|
||||
_cache_ = {}
|
||||
|
||||
profileid = Integer(primary=True)
|
||||
twitchid = String()
|
||||
name = String()
|
||||
created_at = Timestamp()
|
||||
_timestamp = Timestamp()
|
||||
|
||||
|
||||
class Communities(RowModel):
|
||||
"""
|
||||
Schema
|
||||
======
|
||||
CREATE TABLE communities(
|
||||
communityid INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
twitchid TEXT NOT NULL,
|
||||
name TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'communities'
|
||||
_cache_ = {}
|
||||
|
||||
communityid = Integer(primary=True)
|
||||
twitchid = Integer()
|
||||
name = String()
|
||||
created_at = Timestamp()
|
||||
_timestamp = Timestamp()
|
||||
|
||||
|
||||
class Koan(RowModel):
|
||||
"""
|
||||
Schema
|
||||
======
|
||||
CREATE TABLE koans(
|
||||
koanid INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
communityid INTEGER NOT NULL REFERENCES communities ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
"""
|
||||
_tablename_ = 'koans'
|
||||
_cache_ = {}
|
||||
|
||||
koanid = Integer(primary=True)
|
||||
communityid = Integer()
|
||||
name = String()
|
||||
message = String()
|
||||
created_at = Timestamp()
|
||||
_timestamp = Timestamp()
|
||||
|
||||
|
||||
|
||||
class BotData(Registry):
|
||||
user_auth = UserAuth.table
|
||||
|
||||
"""
|
||||
CREATE TABLE user_auth_scopes(
|
||||
userid TEXT NOT NULL REFERENCES user_auth(userid) ON DELETE CASCADE,
|
||||
scope TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
user_auth_scopes = Table('user_auth_scopes')
|
||||
|
||||
bot_channels = BotChannel.table
|
||||
user_profiles = UserProfile.table
|
||||
communities = Communities.table
|
||||
|
||||
koans = Koan.table
|
||||
Reference in New Issue
Block a user