reminder-bot/migration/01-reminder_message_embed.sql

166 lines
17 KiB
MySQL
Raw Permalink Normal View History

2021-06-03 15:42:22 +00:00
USE reminders;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS reminders_new;
DROP TABLE IF EXISTS embed_fields_new;
# create new reminders table structure
CREATE TABLE reminders_new (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`uid` VARCHAR(64) NOT NULL UNIQUE,
`name` VARCHAR(24) NOT NULL DEFAULT 'Reminder',
`channel_id` INT UNSIGNED NOT NULL,
`utc_time` DATETIME NOT NULL,
`timezone` ENUM('Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Asmera', 'Africa/Bamako', 'Africa/Bangui', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Blantyre', 'Africa/Brazzaville', 'Africa/Bujumbura', 'Africa/Cairo', 'Africa/Casablanca', 'Africa/Ceuta', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Dar_es_Salaam', 'Africa/Djibouti', 'Africa/Douala', 'Africa/El_Aaiun', 'Africa/Freetown', 'Africa/Gaborone', 'Africa/Harare', 'Africa/Johannesburg', 'Africa/Juba', 'Africa/Kampala', 'Africa/Khartoum', 'Africa/Kigali', 'Africa/Kinshasa', 'Africa/Lagos', 'Africa/Libreville', 'Africa/Lome', 'Africa/Luanda', 'Africa/Lubumbashi', 'Africa/Lusaka', 'Africa/Malabo', 'Africa/Maputo', 'Africa/Maseru', 'Africa/Mbabane', 'Africa/Mogadishu', 'Africa/Monrovia', 'Africa/Nairobi', 'Africa/Ndjamena', 'Africa/Niamey', 'Africa/Nouakchott', 'Africa/Ouagadougou', 'Africa/Porto-Novo', 'Africa/Sao_Tome', 'Africa/Timbuktu', 'Africa/Tripoli', 'Africa/Tunis', 'Africa/Windhoek', 'America/Adak', 'America/Anchorage', 'America/Anguilla', 'America/Antigua', 'America/Araguaina', 'America/Argentina/Buenos_Aires', 'America/Argentina/Catamarca', 'America/Argentina/ComodRivadavia', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/La_Rioja', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Salta', 'America/Argentina/San_Juan', 'America/Argentina/San_Luis', 'America/Argentina/Tucuman', 'America/Argentina/Ushuaia', 'America/Aruba', 'America/Asuncion', 'America/Atikokan', 'America/Atka', 'America/Bahia', 'America/Bahia_Banderas', 'America/Barbados', 'America/Belem', 'America/Belize', 'America/Blanc-Sablon', 'America/Boa_Vista', 'America/Bogota', 'America/Boise', 'America/Buenos_Aires', 'America/Cambridge_Bay', 'America/Campo_Grande', 'America/Cancun', 'America/Caracas', 'America/Catamarca', 'America/Cayenne', 'America/Cayman', 'America/Chicago', 'America/Chihuahua', 'America/Coral_Harbour', 'America/Cordoba', 'America/Costa_Rica', 'America/Creston', 'America/Cuiaba', 'America/Curacao', 'America/Danmarkshavn', 'America/Dawson', 'America/Dawson_Creek', 'America/Denver', 'America/Detroit', 'America/Dominica', 'America/Edmonton', 'America/Eirunepe', 'America/El_Salvador', 'America/Ensenada', 'America/Fort_Nelson', 'America/Fort_Wayne', 'America/Fortaleza', 'America/Glace_Bay', 'America/Godthab', 'America/Goose_Bay', 'America/Grand_Turk', 'America/Grenada', 'America/Guadeloupe', 'America/Guatemala', 'America/Guayaquil', 'America/Guyana', 'America/Halifax', 'America/Havana', 'America/Hermosillo', 'America/Indiana/Indianapolis', 'America/Indiana/Knox', 'America/Indiana/Marengo', 'America/Indiana/Petersburg', 'America/Indiana/Tell_City', 'America/Indiana/Vevay', 'America/Indiana/Vincennes', 'America/Indiana/Winamac', 'America/Indianapolis', 'America/Inuvik', 'America/Iqaluit', 'America/Jamaica', 'America/Jujuy', 'America/Juneau', 'America/Kentucky/Louisville', 'America/Kentucky/Monticello', 'America/Knox_IN', 'America/Kralendijk', 'America/La_Paz', 'America/Lima', 'America/Los_Angeles', 'America/Louisville', 'America/Lower_Princes', 'America/Maceio', 'America/Managua', 'America/Manaus', 'America/Marigot', 'America/Martinique', 'America/Matamoros', 'America/Mazatlan', 'America/Mendoza', 'America/Menominee', 'America/Merida', 'America/Metlakatla', 'America/Mexico_City', 'America/Miquelon', 'America/Moncton', 'America/Monterrey', 'America/Montevideo', 'America/Montreal', 'America/Montserrat', 'America/Nassau', 'America/New_York', 'America/Nipigon', 'America/Nome', 'America/Noronha', 'America/North_Dakota/Beulah', 'America/North_Dakota/Center', 'America/North_Dakota/New_Salem', 'America/Ojinaga', 'America/Panama', 'America/Pangnirtung', 'America/Paramaribo', 'America/Phoenix', 'America/Port-au-Prince', 'America/Port_of_Spain', 'America/Porto_Acre', 'America/Porto_Velho', 'America/Puerto_Rico', 'America/Punta_Arenas', 'America/Rainy_River', 'America/Rankin_Inlet', 'America/Recife', 'America/Regina', 'America/Resolute', 'America/Rio_Branco', 'America/Rosario', 'America/
`interval` INT UNSIGNED,
`restartable` BOOL NOT NULL DEFAULT 0,
`enabled` BOOL NOT NULL DEFAULT 1,
`expires` DATETIME,
`username` VARCHAR(32) DEFAULT NULL,
`avatar` VARCHAR(512) DEFAULT NULL,
`content` VARCHAR(2048) NOT NULL DEFAULT '',
`tts` BOOL NOT NULL DEFAULT 0,
`attachment` MEDIUMBLOB,
`attachment_name` VARCHAR(260),
`embed_title` VARCHAR(256) NOT NULL DEFAULT '',
`embed_description` VARCHAR(2048) NOT NULL DEFAULT '',
`embed_image_url` VARCHAR(512),
`embed_thumbnail_url` VARCHAR(512),
`embed_footer` VARCHAR(2048) NOT NULL DEFAULT '',
`embed_footer_url` VARCHAR(512),
`embed_author` VARCHAR(256) NOT NULL DEFAULT '',
`embed_author_url` VARCHAR(512),
`embed_color` INT UNSIGNED NOT NULL DEFAULT 0x0,
`pin` BOOL NOT NULL DEFAULT 0,
`set_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`set_by` INT UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
FOREIGN KEY (`channel_id`) REFERENCES channels (`id`) ON DELETE CASCADE,
FOREIGN KEY (`set_by`) REFERENCES users (`id`) ON DELETE SET NULL
2021-06-03 15:42:22 +00:00
# disallow having a reminder as restartable if it has no interval
-- , CONSTRAINT restartable_interval_mutex CHECK (`restartable` = 0 OR `interval` IS NULL)
2021-06-03 15:42:22 +00:00
# disallow disabling if interval is unspecified
-- , CONSTRAINT interval_enabled_mutin CHECK (`enabled` = 1 OR `interval` IS NULL)
2021-06-03 15:42:22 +00:00
# disallow an expiry time if interval is unspecified
-- , CONSTRAINT interval_expires_mutin CHECK (`expires` IS NULL OR `interval` IS NOT NULL)
);
2021-06-03 15:42:22 +00:00
# import data from other tables
INSERT INTO reminders_new (
uid,
name,
channel_id,
`utc_time`,
`interval`,
enabled,
expires,
username,
avatar,
content,
tts,
attachment,
attachment_name,
embed_title,
embed_description,
embed_image_url,
embed_thumbnail_url,
embed_footer,
embed_footer_url,
embed_color,
set_at,
set_by
) SELECT
reminders.uid,
reminders.name,
reminders.channel_id,
DATE_ADD(FROM_UNIXTIME(0), INTERVAL reminders.`time` SECOND),
2021-06-03 15:42:22 +00:00
reminders.`interval`,
reminders.enabled,
reminders.expires,
reminders.username,
reminders.avatar,
messages.content,
messages.tts,
messages.attachment,
messages.attachment_name,
IFNULL(embeds.title, ''),
IFNULL(embeds.description, ''),
embeds.image_url,
embeds.thumbnail_url,
IFNULL(embeds.footer, ''),
embeds.footer_icon,
IFNULL(embeds.color, 0),
reminders.set_at,
reminders.set_by
FROM reminders
INNER JOIN messages ON reminders.message_id = messages.id
LEFT JOIN embeds ON messages.embed_id = embeds.id;
CREATE TABLE embed_fields_new (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(256) NOT NULL,
value VARCHAR(1024) NOT NULL,
inline BOOL NOT NULL DEFAULT 0,
reminder_id INT UNSIGNED,
PRIMARY KEY (id),
2021-06-23 13:04:46 +00:00
FOREIGN KEY (reminder_id) REFERENCES reminders_new (id) ON DELETE CASCADE
2021-06-03 15:42:22 +00:00
);
INSERT INTO embed_fields_new (
title,
value,
inline,
reminder_id
) SELECT
embed_fields.title,
embed_fields.value,
embed_fields.inline,
(SELECT id FROM reminders_new WHERE reminders_new.uid = reminders.uid)
FROM embed_fields
INNER JOIN embeds e on e.id = embed_fields.embed_id
INNER JOIN messages m on e.id = m.embed_id
INNER JOIN reminders on m.id = reminders.message_id;
DROP TABLE IF EXISTS events;
CREATE TABLE events (
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),
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_new(id) ON DELETE SET NULL
);
DROP TABLE reminders;
DROP TABLE embed_fields;
RENAME TABLE reminders_new TO reminders;
RENAME TABLE embed_fields_new TO embed_fields;
2021-06-03 15:42:22 +00:00
SET FOREIGN_KEY_CHECKS = 1;