Fixes and cleans up the sql schema (#18994)

* Fixes and cleasns up the sql schema

* also this

* indent
This commit is contained in:
Kashargul
2026-01-13 06:14:40 +01:00
committed by GitHub
parent 3eccfc5ae5
commit 13566689a1
+71 -57
View File
@@ -1,23 +1,26 @@
CREATE TABLE `admin` (
CREATE TABLE IF NOT EXISTS `admin` (
`ckey` varchar(32) NOT NULL,
`rank` varchar(32) NOT NULL,
`feedback` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `admin_log` (
CREATE TABLE IF NOT EXISTS `admin_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`round_id` int(11) unsigned NULL,
`adminckey` varchar(32) NOT NULL,
`adminip` int(10) unsigned NOT NULL,
`operation` enum('add admin','remove admin','change admin rank','add rank','remove rank','change rank flags') NOT NULL,
`operation` enum(
'add admin','remove admin','change admin rank',
'add rank','remove rank','change rank flags'
) NOT NULL,
`target` varchar(32) NOT NULL,
`log` varchar(1000) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `admin_ranks` (
CREATE TABLE IF NOT EXISTS `admin_ranks` (
`rank` varchar(32) NOT NULL,
`flags` mediumint(5) unsigned NOT NULL,
`exclude_flags` mediumint(5) unsigned NOT NULL,
@@ -26,7 +29,7 @@ CREATE TABLE `admin_ranks` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Table structure for table `erro_ban`
CREATE TABLE `erro_ban` (
CREATE TABLE IF NOT EXISTS `erro_ban` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bantime` datetime NOT NULL,
`serverip` varchar(32) NOT NULL,
@@ -51,10 +54,10 @@ CREATE TABLE `erro_ban` (
`unbanned_computerid` varchar(32) DEFAULT NULL,
`unbanned_ip` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Table structure for table `erro_connection_log`
CREATE TABLE `erro_connection_log` (
CREATE TABLE IF NOT EXISTS `erro_connection_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`serverip` varchar(32) NOT NULL,
@@ -62,10 +65,10 @@ CREATE TABLE `erro_connection_log` (
`ip` varchar(32) NOT NULL,
`computerid` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Table structure for table `erro_feedback`
CREATE TABLE `erro_feedback` (
CREATE TABLE IF NOT EXISTS `erro_feedback` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time` datetime NOT NULL,
`round_id` int(8) NOT NULL,
@@ -73,10 +76,10 @@ CREATE TABLE `erro_feedback` (
`var_value` int(16) DEFAULT NULL,
`details` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- Table structure for table `erro_player`
CREATE TABLE `erro_player` (
CREATE TABLE IF NOT EXISTS `erro_player` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) NOT NULL,
`firstseen` datetime NOT NULL,
@@ -91,7 +94,7 @@ CREATE TABLE `erro_player` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_option`
CREATE TABLE `erro_poll_option` (
CREATE TABLE IF NOT EXISTS `erro_poll_option` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pollid` int(11) NOT NULL,
`text` varchar(255) NOT NULL,
@@ -105,7 +108,7 @@ CREATE TABLE `erro_poll_option` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_question`
CREATE TABLE `erro_poll_question` (
CREATE TABLE IF NOT EXISTS `erro_poll_question` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`polltype` varchar(16) NOT NULL DEFAULT 'OPTION',
`starttime` datetime NOT NULL,
@@ -116,7 +119,7 @@ CREATE TABLE `erro_poll_question` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_textreply`
CREATE TABLE `erro_poll_textreply` (
CREATE TABLE IF NOT EXISTS `erro_poll_textreply` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`pollid` int(11) NOT NULL,
@@ -128,7 +131,7 @@ CREATE TABLE `erro_poll_textreply` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_poll_vote`
CREATE TABLE `erro_poll_vote` (
CREATE TABLE IF NOT EXISTS `erro_poll_vote` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`pollid` int(11) NOT NULL,
@@ -141,7 +144,7 @@ CREATE TABLE `erro_poll_vote` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `erro_privacy`
CREATE TABLE `erro_privacy` (
CREATE TABLE IF NOT EXISTS `erro_privacy` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`datetime` datetime NOT NULL,
`ckey` varchar(32) NOT NULL,
@@ -150,7 +153,7 @@ CREATE TABLE `erro_privacy` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `death`
CREATE TABLE `death` (
CREATE TABLE IF NOT EXISTS `death` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`pod` TEXT NOT NULL COMMENT 'Place of death' ,
`coord` TEXT NOT NULL COMMENT 'X, Y, Z POD' ,
@@ -171,7 +174,7 @@ CREATE TABLE `death` (
-- Table structure for table `karma`
CREATE TABLE `karma` (
CREATE TABLE IF NOT EXISTS `karma` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`spendername` TEXT NOT NULL ,
`spenderkey` TEXT NOT NULL ,
@@ -186,7 +189,7 @@ CREATE TABLE `karma` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `karmatotals`
CREATE TABLE `karmatotals` (
CREATE TABLE IF NOT EXISTS `karmatotals` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`byondkey` TEXT NOT NULL ,
`karma` INT(11) NOT NULL ,
@@ -194,7 +197,7 @@ CREATE TABLE `karmatotals` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `library`
CREATE TABLE `library` (
CREATE TABLE IF NOT EXISTS `library` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`author` TEXT NOT NULL ,
`title` TEXT NOT NULL ,
@@ -204,7 +207,7 @@ CREATE TABLE `library` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `population`
CREATE TABLE `population` (
CREATE TABLE IF NOT EXISTS `population` (
`id` INT(11) NOT NULL AUTO_INCREMENT ,
`playercount` INT(11) NULL DEFAULT NULL ,
`admincount` INT(11) NULL DEFAULT NULL ,
@@ -213,7 +216,7 @@ CREATE TABLE `population` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
-- Table structure for table `vr_player_hours`
CREATE TABLE `vr_player_hours` (
CREATE TABLE IF NOT EXISTS `vr_player_hours` (
`ckey` varchar(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`department` varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`hours` double NOT NULL,
@@ -256,38 +259,32 @@ CREATE TABLE IF NOT EXISTS `chatlogs_logs` (
`created_at` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `chatlogs_ckeys_FK` (`target`),
CONSTRAINT `chatlogs_ckeys_FK` FOREIGN KEY (`target`) REFERENCES `chatlogs_ckeys` (`ckey`)
KEY `idx_chatlogs_logs_round_id` (`round_id`),
CONSTRAINT `chatlogs_ckeys_FK`
FOREIGN KEY (`target`) REFERENCES `chatlogs_ckeys` (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- If you are doing this with the cli you will have to tell it first to use something else as a delimiter instead of ;
-- Otherwise the copy/paste will fail. Do not forget to revert the change in the end.
DELIMITER //
CREATE EVENT `chatlogs_logs_clear_old_logs`
ON SCHEDULE
EVERY 1 MONTH STARTS '2025-01-01 04:00:00'
ON COMPLETION PRESERVE
ENABLE
COMMENT 'This event periodically clears the chatlog logs of very old logs'
DO BEGIN
DELETE FROM chatlogs_logs WHERE created_at < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 3 MONTH)) * 1000;
END
DELIMITER ;
-- Also enable the event_scheduler after creating the event
SET GLOBAL event_scheduler = ON;
-- Table structure for table `chatlogs_rounds`
CREATE TABLE `chatlogs_rounds` (
CREATE TABLE IF NOT EXISTS `chatlogs_rounds` (
`round_id` BIGINT(20) NOT NULL DEFAULT -1,
`ckey` VARCHAR(45) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
PRIMARY KEY (`round_id`, `ckey`) USING BTREE
) ENGINE=InnoDB COLLATE='utf8mb4_uca1400_ai_ci';
-- Table structure for table `whitelist`
CREATE TABLE IF NOT EXISTS `whitelist` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(45) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
`kind` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
`entry` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `ckey_kind_entry` (`ckey`, `kind`, `entry`) USING BTREE
) ENGINE=InnoDB COLLATE='utf8mb4_uca1400_ai_ci';
-- If you are doing this with the cli you will have to tell it first to use something else as a delimiter instead of ;
-- Otherwise the copy/paste will fail. Do not forget to revert the change in the end.
DELIMITER //
CREATE PROCEDURE `chatlogs_rounds_insert`(
CREATE PROCEDURE IF NOT EXISTS `chatlogs_rounds_insert`(
IN `p_round_id` BIGINT,
IN `p_ckey` VARCHAR(45)
)
@@ -298,21 +295,38 @@ SQL SECURITY INVOKER
COMMENT 'Inserts a new row into \'chatlogs_rounds\' and deletes the oldest entry, if the ckey already has 10 round ids stored.'
BEGIN
INSERT IGNORE INTO chatlogs_rounds(round_id, ckey) VALUES (p_round_id, p_ckey);
INSERT IGNORE INTO chatlogs_rounds(round_id, ckey)
VALUES (p_round_id, p_ckey);
IF (SELECT COUNT(*) FROM chatlogs_rounds WHERE ckey = p_ckey) > 10 THEN
DELETE FROM chatlogs_rounds WHERE ckey = p_ckey ORDER BY round_id ASC LIMIT 1;
END IF;
IF (SELECT COUNT(*) FROM chatlogs_rounds WHERE ckey = p_ckey) > 10 THEN
DELETE FROM chatlogs_rounds
WHERE ckey = p_ckey
ORDER BY round_id ASC
LIMIT 1;
END IF;
END//
CREATE EVENT IF NOT EXISTS `chatlogs_logs_clear_old_logs`
ON SCHEDULE EVERY 1 MONTH
STARTS '2025-01-01 04:00:00'
ON COMPLETION PRESERVE
ENABLE
COMMENT 'This event periodically clears the chatlog logs of very old logs'
DO
BEGIN
DELETE FROM chatlogs_logs
WHERE created_at < UNIX_TIMESTAMP(
DATE_SUB(NOW(), INTERVAL 3 MONTH)
) * 1000;
DELETE cr
FROM chatlogs_rounds cr
LEFT JOIN chatlogs_logs cl
ON cr.round_id = cl.round_id
WHERE cl.round_id IS NULL;
END//
END
DELIMITER ;
-- Table structure for table `whitelist`
CREATE TABLE `whitelist` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`ckey` VARCHAR(45) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
`kind` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
`entry` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_uca1400_ai_ci',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `ckey_kind_entry` (`ckey`, `kind`, `entry`) USING BTREE
) ENGINE=InnoDB COLLATE='utf8mb4_uca1400_ai_ci';
-- Also enable the event_scheduler after creating the event
SET GLOBAL event_scheduler = ON;