From 93dcb6bd24978a3845b235fcf14866766a4fb4bb Mon Sep 17 00:00:00 2001 From: Conatum Date: Tue, 19 Oct 2021 13:27:28 +0300 Subject: [PATCH] (data): Migration v4 -> v5. Add migration script for v4 -> v5. Bump data version in schema and constants. --- bot/constants.py | 2 +- data/migration/v4-v5/migration.sql | 36 ++++++++++++++++++++++++++++++ data/schema.sql | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 data/migration/v4-v5/migration.sql diff --git a/bot/constants.py b/bot/constants.py index 35f9ec7c..132ce93d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,2 +1,2 @@ CONFIG_FILE = "config/bot.conf" -DATA_VERSION = 4 +DATA_VERSION = 5 diff --git a/data/migration/v4-v5/migration.sql b/data/migration/v4-v5/migration.sql new file mode 100644 index 00000000..82913d4d --- /dev/null +++ b/data/migration/v4-v5/migration.sql @@ -0,0 +1,36 @@ +CREATE TABLE reaction_role_messages( + messageid BIGINT PRIMARY KEY, + guildid BIGINT NOT NULL REFERENCES guild_config (guildid) ON DELETE CASCADE, + channelid BIGINT NOT NULL, + enabled BOOLEAN DEFAULT TRUE, + required_role BIGINT, + removable BOOLEAN, + maximum INTEGER, + refunds BOOLEAN, + event_log BOOLEAN, + default_price INTEGER +); +CREATE INDEX reaction_role_guilds ON reaction_role_messages (guildid); + +CREATE TABLE reaction_role_reactions( + reactionid SERIAL PRIMARY KEY, + messageid BIGINT NOT NULL REFERENCES reaction_role_messages (messageid) ON DELETE CASCADE, + roleid BIGINT NOT NULL, + emoji_name TEXT, + emoji_id BIGINT, + emoji_animated BOOLEAN, + price INTEGER, + timeout INTEGER +); +CREATE INDEX reaction_role_reaction_messages ON reaction_role_reactions (messageid); + +CREATE TABLE reaction_role_expiring( + guildid BIGINT NOT NULL, + userid BIGINT NOT NULL, + roleid BIGINT NOT NULL, + expiry TIMESTAMPTZ NOT NULL, + reactionid INTEGER REFERENCES reaction_role_reactions (reactionid) ON DELETE SET NULL +); +CREATE UNIQUE INDEX reaction_role_expiry_members ON reaction_role_expiring (guildid, userid, roleid); + +INSERT INTO VersionHistory (version, author) VALUES (5, 'v4-v5 Migration'); diff --git a/data/schema.sql b/data/schema.sql index b9e704a5..fe0158be 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -4,7 +4,7 @@ CREATE TABLE VersionHistory( time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, author TEXT ); -INSERT INTO VersionHistory (version, author) VALUES (4, 'Initial Creation'); +INSERT INTO VersionHistory (version, author) VALUES (5, 'Initial Creation'); CREATE OR REPLACE FUNCTION update_timestamp_column()