2020-09-08 22:08:02 +00:00
|
|
|
SET FOREIGN_KEY_CHECKS=0;
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE guilds (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,
|
|
|
|
guild BIGINT UNSIGNED UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
name VARCHAR(100),
|
|
|
|
|
|
|
|
prefix VARCHAR(5) DEFAULT '$' NOT NULL,
|
|
|
|
timezone VARCHAR(32) DEFAULT 'UTC' NOT NULL,
|
|
|
|
|
|
|
|
default_channel_id INT UNSIGNED,
|
|
|
|
default_username VARCHAR(32) DEFAULT 'Reminder' NOT NULL,
|
|
|
|
default_avatar VARCHAR(512) DEFAULT 'https://raw.githubusercontent.com/reminder-bot/logos/master/Remind_Me_Bot_Logo_PPic.jpg' NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (default_channel_id) REFERENCES reminders.channels(id) ON DELETE SET NULL
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE channels (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,
|
|
|
|
channel BIGINT UNSIGNED UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
name VARCHAR(100),
|
|
|
|
|
|
|
|
nudge SMALLINT NOT NULL DEFAULT 0,
|
|
|
|
blacklisted BOOL NOT NULL DEFAULT FALSE,
|
|
|
|
|
|
|
|
webhook_id BIGINT UNSIGNED UNIQUE,
|
|
|
|
webhook_token TEXT,
|
|
|
|
|
|
|
|
paused BOOL NOT NULL DEFAULT 0,
|
|
|
|
paused_until TIMESTAMP,
|
|
|
|
|
|
|
|
guild_id INT UNSIGNED,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (guild_id) REFERENCES reminders.guilds(id) ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE users (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
user BIGINT UNSIGNED UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
name VARCHAR(37) NOT NULL,
|
|
|
|
|
|
|
|
dm_channel INT UNSIGNED UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
language VARCHAR(2) DEFAULT 'EN' NOT NULL,
|
2020-10-11 17:56:27 +00:00
|
|
|
timezone VARCHAR(32) DEFAULT 'UTC' NOT NULL,
|
2020-12-16 16:53:13 +00:00
|
|
|
meridian_time BOOLEAN DEFAULT 0 NOT NULL,
|
|
|
|
|
2020-09-08 22:08:02 +00:00
|
|
|
allowed_dm BOOLEAN DEFAULT 1 NOT NULL,
|
|
|
|
|
2020-12-16 16:53:13 +00:00
|
|
|
patreon BOOLEAN NOT NULL DEFAULT 0,
|
2020-09-08 22:08:02 +00:00
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (dm_channel) REFERENCES reminders.channels(id) ON DELETE RESTRICT
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE roles (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED UNIQUE NOT NULL AUTO_INCREMENT,
|
|
|
|
role BIGINT UNSIGNED UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
name VARCHAR(100),
|
|
|
|
|
|
|
|
guild_id INT UNSIGNED NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
FOREIGN KEY (guild_id) REFERENCES reminders.guilds(id) ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE embeds (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
title VARCHAR(256) NOT NULL DEFAULT '',
|
|
|
|
description VARCHAR(2048) NOT NULL DEFAULT '',
|
|
|
|
|
|
|
|
image_url VARCHAR(512),
|
|
|
|
thumbnail_url VARCHAR(512),
|
|
|
|
|
|
|
|
footer VARCHAR(2048) NOT NULL DEFAULT '',
|
|
|
|
footer_icon VARCHAR(512),
|
|
|
|
|
|
|
|
color MEDIUMINT UNSIGNED NOT NULL DEFAULT 0x0,
|
|
|
|
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE embed_fields (
|
2020-11-08 15:37:56 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
title VARCHAR(256) NOT NULL DEFAULT '',
|
|
|
|
value VARCHAR(1024) NOT NULL DEFAULT '',
|
|
|
|
inline BOOL NOT NULL DEFAULT 0,
|
|
|
|
embed_id INT UNSIGNED NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (embed_id) REFERENCES embeds(id) ON DELETE CASCADE
|
2020-11-08 15:37:56 +00:00
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE messages (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
content VARCHAR(2048) NOT NULL DEFAULT '',
|
|
|
|
tts BOOL NOT NULL DEFAULT 0,
|
|
|
|
embed_id INT UNSIGNED,
|
|
|
|
|
|
|
|
attachment MEDIUMBLOB,
|
|
|
|
attachment_name VARCHAR(260),
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (embed_id) REFERENCES embeds(id) ON DELETE SET NULL
|
2020-09-08 22:08:02 +00:00
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE reminders (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
uid VARCHAR(64) UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
name VARCHAR(24) NOT NULL DEFAULT 'Reminder',
|
|
|
|
|
|
|
|
message_id INT UNSIGNED NOT NULL,
|
|
|
|
channel_id INT UNSIGNED NOT NULL,
|
|
|
|
|
|
|
|
`time` INT UNSIGNED DEFAULT 0 NOT NULL,
|
|
|
|
`interval` INT UNSIGNED DEFAULT NULL,
|
2020-12-29 22:44:11 +00:00
|
|
|
expires TIMESTAMP DEFAULT NULL,
|
2020-09-08 22:08:02 +00:00
|
|
|
|
|
|
|
enabled BOOLEAN DEFAULT 1 NOT NULL,
|
|
|
|
|
2020-09-14 15:07:44 +00:00
|
|
|
avatar VARCHAR(512),
|
|
|
|
username VARCHAR(32),
|
2020-09-08 22:08:02 +00:00
|
|
|
|
2021-03-14 10:27:30 +00:00
|
|
|
method ENUM('remind', 'natural', 'dashboard', 'todo', 'countdown'),
|
2020-09-08 22:08:02 +00:00
|
|
|
set_at TIMESTAMP DEFAULT NOW(),
|
|
|
|
set_by INT UNSIGNED,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE RESTRICT,
|
|
|
|
FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (set_by) REFERENCES users(id) ON DELETE SET NULL
|
2020-09-08 22:08:02 +00:00
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TRIGGER message_cleanup AFTER DELETE ON reminders
|
2020-09-08 22:08:02 +00:00
|
|
|
FOR EACH ROW
|
2023-03-24 11:11:51 +00:00
|
|
|
DELETE FROM messages WHERE id = OLD.message_id;
|
2020-09-08 22:08:02 +00:00
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TRIGGER embed_cleanup AFTER DELETE ON messages
|
2020-09-08 22:08:02 +00:00
|
|
|
FOR EACH ROW
|
2023-03-24 11:11:51 +00:00
|
|
|
DELETE FROM embeds WHERE id = OLD.embed_id;
|
2020-09-08 22:08:02 +00:00
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE todos (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
user_id INT UNSIGNED,
|
|
|
|
guild_id INT UNSIGNED,
|
|
|
|
channel_id INT UNSIGNED,
|
|
|
|
value VARCHAR(2000) NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
|
|
FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE SET NULL
|
2020-09-08 22:08:02 +00:00
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE command_restrictions (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
role_id INT UNSIGNED NOT NULL,
|
2021-03-14 10:27:30 +00:00
|
|
|
command ENUM('todos', 'natural', 'remind', 'interval', 'timer', 'del', 'look', 'alias', 'countdown') NOT NULL,
|
2020-09-08 22:08:02 +00:00
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE,
|
2020-09-08 22:08:02 +00:00
|
|
|
UNIQUE KEY (`role_id`, `command`)
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE timers (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
start_time TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
|
|
name VARCHAR(32) NOT NULL,
|
|
|
|
owner BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE events (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
`time` TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
|
|
|
|
|
|
event_name ENUM('edit', 'enable', 'disable', 'delete') NOT NULL,
|
|
|
|
bulk_count INT UNSIGNED,
|
|
|
|
|
|
|
|
guild_id INT UNSIGNED NOT NULL,
|
|
|
|
user_id INT UNSIGNED,
|
|
|
|
reminder_id INT UNSIGNED,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
|
|
FOREIGN KEY (reminder_id) REFERENCES reminders(id) ON DELETE SET NULL
|
2020-09-08 22:08:02 +00:00
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE command_aliases (
|
2020-09-08 22:08:02 +00:00
|
|
|
id INT UNSIGNED AUTO_INCREMENT UNIQUE NOT NULL,
|
|
|
|
|
|
|
|
guild_id INT UNSIGNED NOT NULL,
|
|
|
|
name VARCHAR(12) NOT NULL,
|
|
|
|
|
|
|
|
command VARCHAR(2048) NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (guild_id) REFERENCES guilds(id) ON DELETE CASCADE,
|
2020-09-08 22:08:02 +00:00
|
|
|
UNIQUE KEY (`guild_id`, `name`)
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE TABLE guild_users (
|
2020-09-08 22:08:02 +00:00
|
|
|
guild INT UNSIGNED NOT NULL,
|
|
|
|
user INT UNSIGNED NOT NULL,
|
|
|
|
|
|
|
|
can_access BOOL NOT NULL DEFAULT 0,
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
FOREIGN KEY (guild) REFERENCES guilds(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (user) REFERENCES users(id) ON DELETE CASCADE,
|
2020-09-08 22:08:02 +00:00
|
|
|
UNIQUE KEY (guild, user)
|
|
|
|
);
|
|
|
|
|
2023-03-24 11:11:51 +00:00
|
|
|
CREATE EVENT event_cleanup
|
2020-09-08 22:08:02 +00:00
|
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
|
|
|
|
ON COMPLETION PRESERVE
|
2023-03-24 11:11:51 +00:00
|
|
|
DO DELETE FROM events WHERE `time` < DATE_SUB(NOW(), INTERVAL 5 DAY);
|