From 44430079b06c319cfebec88a7f4c61f1667dd0c7 Mon Sep 17 00:00:00 2001 From: Interitio Date: Wed, 3 Sep 2025 23:10:56 +1000 Subject: [PATCH] Factor plugin data out of root schema. --- data/schema.sql | 69 ++++++------------------------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/data/schema.sql b/data/schema.sql index 38b7398..40f6d0a 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -1,10 +1,12 @@ -- Metadata {{{ -CREATE TABLE VersionHistory( - version INTEGER NOT NULL, - time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, - author TEXT +CREATE TABLE version_history( + component TEXT NOT NULL, + from_version INTEGER NOT NULL, + to_version INTEGER NOT NULL, + author TEXT NOT NULL, + _timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(), ); -INSERT INTO VersionHistory (version, author) VALUES (1, 'Initial Creation'); +INSERT INTO version_history (component, from_version, to_version, author) VALUES ('ROOT', 0, 1, 'Initial Creation'); CREATE OR REPLACE FUNCTION update_timestamp_column() @@ -14,9 +16,6 @@ BEGIN RETURN NEW; END; $$ language 'plpgsql'; --- }}} - --- App metadata {{{ CREATE TABLE app_config( appname TEXT PRIMARY KEY, @@ -26,6 +25,7 @@ CREATE TABLE app_config( -- }}} -- Twitch Auth {{{ +INSERT INTO version_history (component, from_version, to_version, author) VALUES ('TWITCH_AUTH', 0, 1, 'Initial Creation'); -- Authorisation tokens allowing us to take actions on behalf of certain users or channels. -- For example, channels we have joined will need to be authorised with a 'channel:bot' scope. @@ -49,7 +49,6 @@ CREATE TABLE user_auth_scopes( 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() ); @@ -59,58 +58,6 @@ CREATE TRIGGER bot_channels_timestamp BEFORE UPDATE ON bot_channels -- }}} --- Twitch user data {{{ ----- Users are internally represented by 'profiles' with a unique profileid ----- This is associated to the user's twitch userid. ----- Any user-specific configuration data or preferences can be added here -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() -); -CREATE TRIGGER user_profiles_timestamp BEFORE UPDATE ON user_profiles - FOR EACH ROW EXECUTE FUNCTION update_timestamp_column(); - - -CREATE UNIQUE INDEX user_profile_twitchid ON user_profiles (twitchid); - --- }}} - --- Twitch channel data {{{ - ----- Similar to user profiles, we associate twitch channels with 'communities' ----- This slight abstraction gives us more flexibility and control over the community and user data. -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() -); -CREATE TRIGGER communities_timestamp BEFORE UPDATE ON communities - FOR EACH ROW EXECUTE FUNCTION update_timestamp_column(); - --- }}} - - --- Koan data {{{ - ----- !koans lists koans. !koan gives a random koan. !koans add name ... !koans del name ... - -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() -); -CREATE TRIGGER koans_timestamp BEFORE UPDATE ON koans - FOR EACH ROW EXECUTE FUNCTION update_timestamp_column(); - --- }}} -- vim: set fdm=marker: