From 2ef19833fc8ff24e0d8a6f366d8ae22dc67a3165 Mon Sep 17 00:00:00 2001 From: ZeldaZach Date: Mon, 20 Jan 2025 01:10:54 -0500 Subject: [PATCH] Support more indices --- servatrice/migrations/servatrice_0031_to_0032.sql | 11 +++++++++++ servatrice/servatrice.sql | 15 +++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 servatrice/migrations/servatrice_0031_to_0032.sql diff --git a/servatrice/migrations/servatrice_0031_to_0032.sql b/servatrice/migrations/servatrice_0031_to_0032.sql new file mode 100644 index 000000000..dd3a1334c --- /dev/null +++ b/servatrice/migrations/servatrice_0031_to_0032.sql @@ -0,0 +1,11 @@ +-- Servatrice db migration from version 31 to version 32 + +ALTER TABLE cockatrice_users ADD INDEX `idx_clientid` (`clientid`); +ALTER TABLE cockatrice_sessions ADD INDEX `idx_clientid` (`clientid`); +ALTER TABLE cockatrice_sessions ADD INDEX `idx_ip_address` (`ip_address`); +ALTER TABLE cockatrice_bans ADD INDEX `idx_user_name` (`user_name`); +ALTER TABLE cockatrice_warnings ADD INDEX `idx_time_of` (`time_of`); +ALTER TABLE cockatrice_warnings ADD INDEX `idx_user_name` (`user_name`); +ALTER TABLE cockatrice_log ADD INDEX `idx_log_time` (`log_time`); + +UPDATE cockatrice_schema_version SET version=32 WHERE version=31; diff --git a/servatrice/servatrice.sql b/servatrice/servatrice.sql index 5fca8678c..9e9f304d3 100644 --- a/servatrice/servatrice.sql +++ b/servatrice/servatrice.sql @@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` ( PRIMARY KEY (`version`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; -INSERT INTO cockatrice_schema_version VALUES(31); +INSERT INTO cockatrice_schema_version VALUES(32); -- users and user data tables CREATE TABLE IF NOT EXISTS `cockatrice_users` ( @@ -47,7 +47,8 @@ CREATE TABLE IF NOT EXISTS `cockatrice_users` ( KEY `email` (`email`), INDEX `idx_admin` (`admin`), INDEX `idx_active` (`active`), - INDEX `idx_privlevel` (`privlevel`) + INDEX `idx_privlevel` (`privlevel`), + INDEX `idx_clientid` (`clientid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` ( @@ -194,7 +195,9 @@ CREATE TABLE IF NOT EXISTS `cockatrice_sessions` ( `connection_type` ENUM('tcp', 'websocket'), PRIMARY KEY (`id`), KEY `username` (`user_name`), - INDEX `idx_start_time` (`start_time`) + INDEX `idx_start_time` (`start_time`), + INDEX `idx_clientid` (`clientid`), + INDEX `idx_ip_address` (`ip_address`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; -- server moderation @@ -210,6 +213,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_bans` ( PRIMARY KEY (`user_name`,`time_from`), KEY `time_from` (`time_from`,`ip_address`), KEY `ip_address` (`ip_address`), + INDEX `idx_user_name` (`user_name`), FOREIGN KEY(`id_admin`) REFERENCES `cockatrice_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; @@ -220,7 +224,9 @@ CREATE TABLE IF NOT EXISTS `cockatrice_warnings` ( `reason` text NOT NULL, `time_of` datetime NOT NULL, `clientid` varchar(15) NOT NULL, - PRIMARY KEY (`user_id`,`time_of`) + PRIMARY KEY (`user_id`,`time_of`), + INDEX `idx_time_of` (`time_of`), + INDEX `idx_user_name` (`user_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `cockatrice_log` ( @@ -236,6 +242,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_log` ( KEY `sender_ip` (`sender_ip`), KEY `target_id` (`target_id`), KEY `target_name` (`target_name`), + INDEX `idx_log_time` (`log_time`), FOREIGN KEY(`sender_id`) REFERENCES `cockatrice_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE -- No FK on target_id, it can be zero ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;