1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

refactor: Add mod_log and related tables to database schema

This commit is contained in:
wlinator 2024-07-17 12:37:40 -04:00
parent e3494f36f3
commit 71b765f815

View file

@ -0,0 +1,61 @@
CREATE TABLE IF NOT EXISTS mod_log (
id SERIAL PRIMARY KEY,
guild_id BIGINT UNSIGNED NOT NULL,
channel_id BIGINT UNSIGNED NOT NULL,
is_enabled BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS action_types (
id SERIAL PRIMARY KEY,
name ENUM(
'WARN',
'TIMEOUT',
'UNTIMEOUT',
'KICK',
'BAN',
'UNBAN',
'SOFTBAN',
'TEMPBAN',
'NOTE',
'MUTE',
'UNMUTE',
'DEAFEN',
'UNDEAFEN'
) NOT NULL
);
CREATE TABLE IF NOT EXISTS cases (
id SERIAL PRIMARY KEY,
guild_id BIGINT UNSIGNED NOT NULL,
case_number INT UNSIGNED NOT NULL,
target_id BIGINT UNSIGNED NOT NULL,
moderator_id BIGINT UNSIGNED NOT NULL,
action_type_id INT UNSIGNED NOT NULL,
reason TEXT,
duration INT UNSIGNED, -- for timeouts
expires_at TIMESTAMP, -- for tempbans & mutes
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (action_type_id) REFERENCES action_types(id)
);
CREATE TABLE IF NOT EXISTS permissions (
id SERIAL PRIMARY KEY,
guild_id BIGINT UNSIGNED NOT NULL,
role_id BIGINT UNSIGNED NOT NULL,
action_type_id INT UNSIGNED NOT NULL,
is_allowed BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (action_type_id) REFERENCES action_types(id)
);
CREATE INDEX idx_cases_guild_id ON cases(guild_id);
CREATE INDEX idx_cases_target_id ON cases(target_id);
CREATE INDEX idx_cases_moderator_id ON cases(moderator_id);
CREATE INDEX idx_cases_action_type_id ON cases(action_type_id);
CREATE INDEX idx_permissions_guild_id ON permissions(guild_id);
CREATE INDEX idx_permissions_role_id ON permissions(role_id);
CREATE INDEX idx_permissions_action_type_id ON permissions(action_type_id);