diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index a553cef999cc0..7d90d7fcc57bd 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -201,6 +201,15 @@ This prevents nesting levels from getting deeper then they need to be. * Files and path accessed and referenced by code above simply being #included should be strictly lowercase to avoid issues on filesystems where case matters. +### SQL +* Do not use the shorthand sql insert format (where no column names are specified) because it unnecessarily breaks all queries on minor column changes and prevents using these tables for tracking outside related info such as in a connected site/forum. + +* All changes to the database's layout(schema) must be specified in the database changelog in SQL, as well as reflected in the schema files + +* Queries must never specify the database, be it in code, or in text files in the repo. + + + ### Other Notes * Code should be modular where possible, if you are working on a new class then it is best if you put it in a new file. @@ -210,8 +219,6 @@ This prevents nesting levels from getting deeper then they need to be. * Do not divide when you can easily convert it to a multiplication. (ie `4/2` should be done as `4*0.5`) -* Do not use the shorthand sql insert format (where no column names are specified) because it unnecessarily breaks all queries on minor column changes and prevents using these tables for tracking outside related info such as in a connected site/forum. - #### Enforced not enforced The following different coding styles are not only not enforced, but it is generally frowned upon to change them over from one to the other for little reason: diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 43765681eea24..2bfc43c9a094b 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -2,7 +2,7 @@ Modified table 'poll_option', removing the column 'percentagecalc'. -ALTER TABLE `feedback`.`poll_option` DROP COLUMN `percentagecalc` +ALTER TABLE `poll_option` DROP COLUMN `percentagecalc` Remember to add a prefix to the table name if you use them. @@ -13,11 +13,11 @@ Remember to add a prefix to the table name if you use them. Modified table 'death', adding column 'round_id', removing column 'gender' and replacing column 'coord' with the columns 'x_coord', 'y_coord' and 'z_coord'. START TRANSACTION; -ALTER TABLE `feedback`.`death` DROP COLUMN `gender`, ADD COLUMN `x_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `coord`, ADD COLUMN `y_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `x_coord`, ADD COLUMN `z_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `y_coord`, ADD COLUMN `round_id` INT(11) NOT NULL AFTER `server_port`; +ALTER TABLE `death` DROP COLUMN `gender`, ADD COLUMN `x_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `coord`, ADD COLUMN `y_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `x_coord`, ADD COLUMN `z_coord` SMALLINT(5) UNSIGNED NOT NULL AFTER `y_coord`, ADD COLUMN `round_id` INT(11) NOT NULL AFTER `server_port`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`death` SET `x_coord` = SUBSTRING_INDEX(`coord`, ',', 1), `y_coord` = SUBSTRING_INDEX(SUBSTRING_INDEX(`coord`, ',', 2), ',', -1), `z_coord` = SUBSTRING_INDEX(`coord`, ',', -1); +UPDATE `death` SET `x_coord` = SUBSTRING_INDEX(`coord`, ',', 1), `y_coord` = SUBSTRING_INDEX(SUBSTRING_INDEX(`coord`, ',', 2), ',', -1), `z_coord` = SUBSTRING_INDEX(`coord`, ',', -1); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`death` DROP COLUMN `coord`; +ALTER TABLE `death` DROP COLUMN `coord`; COMMIT; Remember to add a prefix to the table name if you use them. @@ -36,7 +36,7 @@ UPDATE death SET coord = CONCAT(SUBSTRING_INDEX(coord, ',', 2), ', ', CASE TRIM( Modified table 'ban', adding the column 'round_id'. -ALTER TABLE `feedback`.`ban` ADD COLUMN `round_id` INT(11) NOT NULL AFTER `server_port` +ALTER TABLE `ban` ADD COLUMN `round_id` INT(11) NOT NULL AFTER `server_port` Remember to add a prefix to the table name if you use them. @@ -48,14 +48,14 @@ Created table `round` to replace tracking of the datapoints 'round_start', 'roun Once created this table is populated with rows from the `feedback` table. START TRANSACTION; -CREATE TABLE `feedback`.`round` (`id` INT(11) NOT NULL AUTO_INCREMENT, `start_datetime` DATETIME NOT NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, `commit_hash` CHAR(40) NULL, `game_mode` VARCHAR(32) NULL, `game_mode_result` VARCHAR(64) NULL, `end_state` VARCHAR(64) NULL, `shuttle_name` VARCHAR(64) NULL, `map_name` VARCHAR(32) NULL, `station_name` VARCHAR(80) NULL, PRIMARY KEY (`id`)); -ALTER TABLE `feedback`.`feedback` ADD INDEX `tmp` (`round_id` ASC, `var_name` ASC); -INSERT INTO `feedback`.`round` +CREATE TABLE `round` (`id` INT(11) NOT NULL AUTO_INCREMENT, `start_datetime` DATETIME NOT NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, `commit_hash` CHAR(40) NULL, `game_mode` VARCHAR(32) NULL, `game_mode_result` VARCHAR(64) NULL, `end_state` VARCHAR(64) NULL, `shuttle_name` VARCHAR(64) NULL, `map_name` VARCHAR(32) NULL, `station_name` VARCHAR(80) NULL, PRIMARY KEY (`id`)); +ALTER TABLE `feedback` ADD INDEX `tmp` (`round_id` ASC, `var_name` ASC); +INSERT INTO `round` (`id`, `start_datetime`, `end_datetime`, `server_ip`, `server_port`, `commit_hash`, `game_mode`, `game_mode_result`, `end_state`, `shuttle_name`, `map_name`, `station_name`) SELECT DISTINCT ri.round_id, IFNULL(STR_TO_DATE(st.details,'%a %b %e %H:%i:%s %Y'), TIMESTAMP(0)), STR_TO_DATE(et.details,'%a %b %e %H:%i:%s %Y'), IFNULL(INET_ATON(SUBSTRING_INDEX(IF(si.details = '', '0', IF(SUBSTRING_INDEX(si.details, ':', 1) LIKE '%_._%', si.details, '0')), ':', 1)), INET_ATON(0)), IFNULL(IF(si.details LIKE '%:_%', CAST(SUBSTRING_INDEX(si.details, ':', -1) AS UNSIGNED), '0'), '0'), ch.details, gm.details, mr.details, IFNULL(es.details, ep.details), ss.details, mn.details, sn.details -FROM `feedback`.`feedback`AS ri -LEFT JOIN `feedback`.`feedback` AS st ON ri.round_id = st.round_id AND st.var_name = "round_start" LEFT JOIN `feedback`.`feedback` AS et ON ri.round_id = et.round_id AND et.var_name = "round_end" LEFT JOIN `feedback`.`feedback` AS si ON ri.round_id = si.round_id AND si.var_name = "server_ip" LEFT JOIN `feedback`.`feedback` AS ch ON ri.round_id = ch.round_id AND ch.var_name = "revision" LEFT JOIN `feedback`.`feedback` AS gm ON ri.round_id = gm.round_id AND gm.var_name = "game_mode" LEFT JOIN `feedback`.`feedback` AS mr ON ri.round_id = mr.round_id AND mr.var_name = "round_end_result" LEFT JOIN `feedback`.`feedback` AS es ON ri.round_id = es.round_id AND es.var_name = "end_state" LEFT JOIN `feedback`.`feedback` AS ep ON ri.round_id = ep.round_id AND ep.var_name = "end_proper" LEFT JOIN `feedback`.`feedback` AS ss ON ri.round_id = ss.round_id AND ss.var_name = "emergency_shuttle" LEFT JOIN `feedback`.`feedback` AS mn ON ri.round_id = mn.round_id AND mn.var_name = "map_name" LEFT JOIN `feedback`.`feedback` AS sn ON ri.round_id = sn.round_id AND sn.var_name = "station_renames"; -ALTER TABLE `feedback`.`feedback` DROP INDEX `tmp`; +FROM `feedback`AS ri +LEFT JOIN `feedback` AS st ON ri.round_id = st.round_id AND st.var_name = "round_start" LEFT JOIN `feedback` AS et ON ri.round_id = et.round_id AND et.var_name = "round_end" LEFT JOIN `feedback` AS si ON ri.round_id = si.round_id AND si.var_name = "server_ip" LEFT JOIN `feedback` AS ch ON ri.round_id = ch.round_id AND ch.var_name = "revision" LEFT JOIN `feedback` AS gm ON ri.round_id = gm.round_id AND gm.var_name = "game_mode" LEFT JOIN `feedback` AS mr ON ri.round_id = mr.round_id AND mr.var_name = "round_end_result" LEFT JOIN `feedback` AS es ON ri.round_id = es.round_id AND es.var_name = "end_state" LEFT JOIN `feedback` AS ep ON ri.round_id = ep.round_id AND ep.var_name = "end_proper" LEFT JOIN `feedback` AS ss ON ri.round_id = ss.round_id AND ss.var_name = "emergency_shuttle" LEFT JOIN `feedback` AS mn ON ri.round_id = mn.round_id AND mn.var_name = "map_name" LEFT JOIN `feedback` AS sn ON ri.round_id = sn.round_id AND sn.var_name = "station_renames"; +ALTER TABLE `feedback` DROP INDEX `tmp`; COMMIT; It's not necessary to delete the rows from the `feedback` table but henceforth these datapoints will be in the `round` table. @@ -68,7 +68,7 @@ Remember to add a prefix to the table names if you use them Modified table 'player', adding the column 'accountjoindate', removing the column 'id' and making the column 'ckey' the primary key. -ALTER TABLE `feedback`.`player` DROP COLUMN `id`, ADD COLUMN `accountjoindate` DATE NULL AFTER `lastadminrank`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`), DROP INDEX `ckey`; +ALTER TABLE `player` DROP COLUMN `id`, ADD COLUMN `accountjoindate` DATE NULL AFTER `lastadminrank`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`), DROP INDEX `ckey`; Remember to add a prefix to the table name if you use them. @@ -78,9 +78,9 @@ Remember to add a prefix to the table name if you use them. Modified table 'death', adding the columns 'toxloss', 'cloneloss', and 'staminaloss' and table 'legacy_population', adding the columns 'server_ip' and 'server_port'. -ALTER TABLE `feedback`.`death` ADD COLUMN `toxloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `oxyloss`, ADD COLUMN `cloneloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `toxloss`, ADD COLUMN `staminaloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `cloneloss`; +ALTER TABLE `death` ADD COLUMN `toxloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `oxyloss`, ADD COLUMN `cloneloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `toxloss`, ADD COLUMN `staminaloss` SMALLINT(5) UNSIGNED NOT NULL AFTER `cloneloss`; -ALTER TABLE `feedback`.`legacy_population` ADD COLUMN `server_ip` INT(10) UNSIGNED NOT NULL AFTER `time`, ADD COLUMN `server_port` SMALLINT(5) UNSIGNED NOT NULL AFTER `server_ip`; +ALTER TABLE `legacy_population` ADD COLUMN `server_ip` INT(10) UNSIGNED NOT NULL AFTER `time`, ADD COLUMN `server_port` SMALLINT(5) UNSIGNED NOT NULL AFTER `server_ip`; Remember to add a prefix to the table name if you use them. @@ -112,18 +112,18 @@ Created table 'messages' to supersede the 'notes', 'memos', and 'watchlist' tabl To create this new table run the following command: -CREATE TABLE `feedback`.`messages` (`id` INT(11) NOT NULL AUTO_INCREMENT , `type` VARCHAR(32) NOT NULL , `targetckey` VARCHAR(32) NOT NULL , `adminckey` VARCHAR(32) NOT NULL , `text` TEXT NOT NULL , `timestamp` DATETIME NOT NULL , `server` VARCHAR(32) NULL , `secret` TINYINT(1) NULL DEFAULT 1 , `lasteditor` VARCHAR(32) NULL , `edits` TEXT NULL , PRIMARY KEY (`id`) ) +CREATE TABLE `messages` (`id` INT(11) NOT NULL AUTO_INCREMENT , `type` VARCHAR(32) NOT NULL , `targetckey` VARCHAR(32) NOT NULL , `adminckey` VARCHAR(32) NOT NULL , `text` TEXT NOT NULL , `timestamp` DATETIME NOT NULL , `server` VARCHAR(32) NULL , `secret` TINYINT(1) NULL DEFAULT 1 , `lasteditor` VARCHAR(32) NULL , `edits` TEXT NULL , PRIMARY KEY (`id`) ) To copy the contents of the 'notes', 'memos', and 'watchlist' tables to this new table run the following commands: -INSERT INTO `feedback`.`messages` -(`id`,`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`server`,`secret`,`lasteditor`,`edits`) SELECT `id`, "note", `ckey`, `adminckey`, `notetext`, `timestamp`, `server`, `secret`, `last_editor`, `edits` FROM `feedback`.`notes` +INSERT INTO `messages` +(`id`,`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`server`,`secret`,`lasteditor`,`edits`) SELECT `id`, "note", `ckey`, `adminckey`, `notetext`, `timestamp`, `server`, `secret`, `last_editor`, `edits` FROM `notes` -INSERT INTO `feedback`.`messages` -(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "memo", `ckey`, `ckey`, `memotext`, `timestamp`, `last_editor`, `edits` FROM `feedback`.`memo` +INSERT INTO `messages` +(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "memo", `ckey`, `ckey`, `memotext`, `timestamp`, `last_editor`, `edits` FROM `memo` -INSERT INTO `feedback`.`messages` -(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "watchlist entry", `ckey`, `adminckey`, `reason`, `timestamp`, `last_editor`, `edits` FROM `feedback`.`watch` +INSERT INTO `messages` +(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "watchlist entry", `ckey`, `adminckey`, `reason`, `timestamp`, `last_editor`, `edits` FROM `watch` It's not necessary to delete the 'notes', 'memos', and 'watchlist' tables but they will no longer be used. @@ -135,7 +135,7 @@ Remember to add a prefix to the table names if you use them Modified table 'notes', adding column 'secret'. -ALTER TABLE `feedback`.`notes` ADD COLUMN `secret` TINYINT(1) NOT NULL DEFAULT '1' AFTER `server` +ALTER TABLE `notes` ADD COLUMN `secret` TINYINT(1) NOT NULL DEFAULT '1' AFTER `server` Remember to add a prefix to the table name if you use them @@ -145,7 +145,7 @@ Remember to add a prefix to the table name if you use them Changed appearance bans to be jobbans. -UPDATE 'feedback'.`ban` SET `job` = "appearance", `bantype` = "JOB_PERMABAN" WHERE `bantype` = "APPEARANCE_PERMABAN" +UPDATE `ban` SET `job` = "appearance", `bantype` = "JOB_PERMABAN" WHERE `bantype` = "APPEARANCE_PERMABAN" Remember to add a prefix to the table name if you use them @@ -155,7 +155,7 @@ Remember to add a prefix to the table name if you use them Modified table 'poll_question', adding column 'dontshow' which was recently added to the server schema. -ALTER TABLE `feedback`.`poll_question` ADD COLUMN `dontshow` TINYINT(1) NOT NULL DEFAULT '0' AFTER `for_trialmin` +ALTER TABLE `poll_question` ADD COLUMN `dontshow` TINYINT(1) NOT NULL DEFAULT '0' AFTER `for_trialmin` Remember to add a prefix to the table name if you use them @@ -165,7 +165,7 @@ Remember to add a prefix to the table name if you use them Added ipintel table, only required if ip intel is enabled in the config -CREATE TABLE `ipintel` ( +CREATE TABLE `ipintel` ( `ip` INT UNSIGNED NOT NULL , `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL , `intel` REAL NOT NULL DEFAULT '0', @@ -178,7 +178,7 @@ PRIMARY KEY ( `ip` ) Modified table 'poll_question', adding columns 'createdby_ckey', 'createdby_ip' and 'for_trialmin' to bring it inline with the schema used by the tg servers. -ALTER TABLE `feedback`.`poll_question` ADD COLUMN `createdby_ckey` VARCHAR(45) NULL DEFAULT NULL AFTER `multiplechoiceoptions`, ADD COLUMN `createdby_ip` VARCHAR(45) NULL DEFAULT NULL AFTER `createdby_ckey`, ADD COLUMN `for_trialmin` VARCHAR(45) NULL DEFAULT NULL AFTER `createdby_ip` +ALTER TABLE `poll_question` ADD COLUMN `createdby_ckey` VARCHAR(45) NULL DEFAULT NULL AFTER `multiplechoiceoptions`, ADD COLUMN `createdby_ip` VARCHAR(45) NULL DEFAULT NULL AFTER `createdby_ckey`, ADD COLUMN `for_trialmin` VARCHAR(45) NULL DEFAULT NULL AFTER `createdby_ip` Remember to add a prefix to the table name if you use them @@ -188,7 +188,7 @@ Remember to add a prefix to the table name if you use them Modified table 'watch', removing 'id' column, making 'ckey' primary and adding the columns 'timestamp', 'adminckey', 'last_editor' and 'edits'. -ALTER TABLE `feedback`.`watch` DROP COLUMN `id`, ADD COLUMN `timestamp` datetime NOT NULL AFTER `reason`, ADD COLUMN `adminckey` varchar(32) NOT NULL AFTER `timestamp`, ADD COLUMN `last_editor` varchar(32) NULL AFTER `adminckey`, ADD COLUMN `edits` text NULL AFTER `last_editor`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`) +ALTER TABLE `watch` DROP COLUMN `id`, ADD COLUMN `timestamp` datetime NOT NULL AFTER `reason`, ADD COLUMN `adminckey` varchar(32) NOT NULL AFTER `timestamp`, ADD COLUMN `last_editor` varchar(32) NULL AFTER `adminckey`, ADD COLUMN `edits` text NULL AFTER `last_editor`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`) Remember to add a prefix to the table name if you use them. @@ -210,7 +210,7 @@ Remember to add prefix to the table name if you use them. Modified table 'memo', removing 'id' column and making 'ckey' primary. -ALTER TABLE `feedback`.`memo` DROP COLUMN `id`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`) +ALTER TABLE `memo` DROP COLUMN `id`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`) Remember to add prefix to the table name if you use them. diff --git a/SQL/optimisations_2017-02-19.sql b/SQL/optimisations_2017-02-19.sql index 674cbcf9c621e..1bb19cc66774f 100644 --- a/SQL/optimisations_2017-02-19.sql +++ b/SQL/optimisations_2017-02-19.sql @@ -38,7 +38,7 @@ Take note some columns have been renamed, removed or changed type. Any services ----------------------------------------------------*/ START TRANSACTION; -ALTER TABLE `feedback`.`ban` +ALTER TABLE `ban` DROP COLUMN `rounds` , CHANGE COLUMN `bantype` `bantype` ENUM('PERMABAN', 'TEMPBAN', 'JOB_PERMABAN', 'JOB_TEMPBAN', 'ADMIN_PERMABAN', 'ADMIN_TEMPBAN') NOT NULL , CHANGE COLUMN `reason` `reason` VARCHAR(2048) NOT NULL @@ -51,14 +51,14 @@ ALTER TABLE `feedback`.`ban` , ADD COLUMN `a_ipTEMP` INT UNSIGNED NOT NULL AFTER `a_ip` , ADD COLUMN `unbanned_ipTEMP` INT UNSIGNED NULL DEFAULT NULL AFTER `unbanned_ip`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`ban` +UPDATE `ban` SET `server_ip` = INET_ATON(SUBSTRING_INDEX(IF(`serverip` = '', '0', IF(SUBSTRING_INDEX(`serverip`, ':', 1) LIKE '%_._%', `serverip`, '0')), ':', 1)) , `server_port` = IF(`serverip` LIKE '%:_%', CAST(SUBSTRING_INDEX(`serverip`, ':', -1) AS UNSIGNED), '0') , `ipTEMP` = INET_ATON(IF(`ip` LIKE '%_._%', `ip`, '0')) , `a_ipTEMP` = INET_ATON(IF(`a_ip` LIKE '%_._%', `a_ip`, '0')) , `unbanned_ipTEMP` = INET_ATON(IF(`unbanned_ip` LIKE '%_._%', `unbanned_ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`ban` +ALTER TABLE `ban` DROP COLUMN `unbanned_ip` , DROP COLUMN `a_ip` , DROP COLUMN `ip` @@ -69,17 +69,17 @@ ALTER TABLE `feedback`.`ban` COMMIT; START TRANSACTION; -ALTER TABLE `feedback`.`connection_log` +ALTER TABLE `connection_log` ADD COLUMN `server_ip` INT UNSIGNED NOT NULL AFTER `serverip` , ADD COLUMN `server_port` SMALLINT UNSIGNED NOT NULL AFTER `server_ip` , ADD COLUMN `ipTEMP` INT UNSIGNED NOT NULL AFTER `ip`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`connection_log` +UPDATE `connection_log` SET `server_ip` = INET_ATON(SUBSTRING_INDEX(IF(`serverip` = '', '0', IF(SUBSTRING_INDEX(`serverip`, ':', 1) LIKE '%_._%', `serverip`, '0')), ':', 1)) , `server_port` = IF(`serverip` LIKE '%:_%', CAST(SUBSTRING_INDEX(`serverip`, ':', -1) AS UNSIGNED), '0') , `ipTEMP` = INET_ATON(IF(`ip` LIKE '%_._%', `ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`connection_log` +ALTER TABLE `connection_log` DROP COLUMN `ip` , DROP COLUMN `serverip` , CHANGE COLUMN `ipTEMP` `ip` INT(10) UNSIGNED NOT NULL; @@ -87,12 +87,12 @@ COMMIT; START TRANSACTION; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`death` +UPDATE `death` SET `bruteloss` = LEAST(`bruteloss`, 65535) , `brainloss` = LEAST(`brainloss`, 65535) , `fireloss` = LEAST(`fireloss`, 65535) , `oxyloss` = LEAST(`oxyloss`, 65535); -ALTER TABLE `feedback`.`death` +ALTER TABLE `death` CHANGE COLUMN `pod` `pod` VARCHAR(50) NOT NULL , CHANGE COLUMN `coord` `coord` VARCHAR(32) NOT NULL , CHANGE COLUMN `mapname` `mapname` VARCHAR(32) NOT NULL @@ -109,39 +109,39 @@ ALTER TABLE `feedback`.`death` , CHANGE COLUMN `oxyloss` `oxyloss` SMALLINT UNSIGNED NOT NULL , ADD COLUMN `server_ip` INT UNSIGNED NOT NULL AFTER `server` , ADD COLUMN `server_port` SMALLINT UNSIGNED NOT NULL AFTER `server_ip`; -UPDATE `feedback`.`death` +UPDATE `death` SET `server_ip` = INET_ATON(SUBSTRING_INDEX(IF(`server` = '', '0', IF(SUBSTRING_INDEX(`server`, ':', 1) LIKE '%_._%', `server`, '0')), ':', 1)) , `server_port` = IF(`server` LIKE '%:_%', CAST(SUBSTRING_INDEX(`server`, ':', -1) AS UNSIGNED), '0'); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`death` +ALTER TABLE `death` DROP COLUMN `server`; COMMIT; -ALTER TABLE `feedback`.`library` +ALTER TABLE `library` CHANGE COLUMN `category` `category` ENUM('Any', 'Fiction', 'Non-Fiction', 'Adult', 'Reference', 'Religion') NOT NULL , CHANGE COLUMN `ckey` `ckey` VARCHAR(32) NOT NULL DEFAULT 'LEGACY' , CHANGE COLUMN `datetime` `datetime` DATETIME NOT NULL , CHANGE COLUMN `deleted` `deleted` TINYINT(1) UNSIGNED NULL DEFAULT NULL; -ALTER TABLE `feedback`.`messages` +ALTER TABLE `messages` CHANGE COLUMN `type` `type` ENUM('memo', 'message', 'message sent', 'note', 'watchlist entry') NOT NULL , CHANGE COLUMN `text` `text` VARCHAR(2048) NOT NULL , CHANGE COLUMN `secret` `secret` TINYINT(1) UNSIGNED NOT NULL; START TRANSACTION; -ALTER TABLE `feedback`.`player` +ALTER TABLE `player` ADD COLUMN `ipTEMP` INT UNSIGNED NOT NULL AFTER `ip`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`player` +UPDATE `player` SET `ipTEMP` = INET_ATON(IF(`ip` LIKE '%_._%', `ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`player` +ALTER TABLE `player` DROP COLUMN `ip` , CHANGE COLUMN `ipTEMP` `ip` INT(10) UNSIGNED NOT NULL; COMMIT; START TRANSACTION; -ALTER TABLE `feedback`.`poll_question` +ALTER TABLE `poll_question` CHANGE COLUMN `polltype` `polltype` ENUM('OPTION', 'TEXT', 'NUMVAL', 'MULTICHOICE', 'IRV') NOT NULL , CHANGE COLUMN `adminonly` `adminonly` TINYINT(1) UNSIGNED NOT NULL , CHANGE COLUMN `createdby_ckey` `createdby_ckey` VARCHAR(32) NULL DEFAULT NULL @@ -149,36 +149,36 @@ ALTER TABLE `feedback`.`poll_question` , ADD COLUMN `createdby_ipTEMP` INT UNSIGNED NOT NULL AFTER `createdby_ip` , DROP COLUMN `for_trialmin`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`poll_question` +UPDATE `poll_question` SET `createdby_ipTEMP` = INET_ATON(IF(`createdby_ip` LIKE '%_._%', `createdby_ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`poll_question` +ALTER TABLE `poll_question` DROP COLUMN `createdby_ip` , CHANGE COLUMN `createdby_ipTEMP` `createdby_ip` INT(10) UNSIGNED NOT NULL; COMMIT; START TRANSACTION; -ALTER TABLE `feedback`.`poll_textreply` +ALTER TABLE `poll_textreply` CHANGE COLUMN `replytext` `replytext` VARCHAR(2048) NOT NULL , ADD COLUMN `ipTEMP` INT UNSIGNED NOT NULL AFTER `ip`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`poll_textreply` +UPDATE `poll_textreply` SET `ipTEMP` = INET_ATON(IF(`ip` LIKE '%_._%', `ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`poll_textreply` +ALTER TABLE `poll_textreply` DROP COLUMN `ip` , CHANGE COLUMN `ipTEMP` `ip` INT(10) UNSIGNED NOT NULL; COMMIT; START TRANSACTION; -ALTER TABLE `feedback`.`poll_vote` +ALTER TABLE `poll_vote` CHANGE COLUMN `ckey` `ckey` VARCHAR(32) NOT NULL , ADD COLUMN `ipTEMP` INT UNSIGNED NOT NULL AFTER `ip`; SET SQL_SAFE_UPDATES = 0; -UPDATE `feedback`.`poll_vote` +UPDATE `poll_vote` SET `ipTEMP` = INET_ATON(IF(`ip` LIKE '%_._%', `ip`, '0')); SET SQL_SAFE_UPDATES = 1; -ALTER TABLE `feedback`.`poll_vote` +ALTER TABLE `poll_vote` DROP COLUMN `ip` , CHANGE COLUMN `ipTEMP` `ip` INT(10) UNSIGNED NOT NULL; COMMIT; @@ -191,39 +191,39 @@ You may find it helpful to modify or create your own indexes if you utilise addi ----------------------------------------------------*/ -ALTER TABLE `feedback`.`ban` +ALTER TABLE `ban` ADD INDEX `idx_ban_checkban` (`ckey` ASC, `bantype` ASC, `expiration_time` ASC, `unbanned` ASC, `job` ASC) , ADD INDEX `idx_ban_isbanned` (`ckey` ASC, `ip` ASC, `computerid` ASC, `bantype` ASC, `expiration_time` ASC, `unbanned` ASC) , ADD INDEX `idx_ban_count` (`id` ASC, `a_ckey` ASC, `bantype` ASC, `expiration_time` ASC, `unbanned` ASC); -ALTER TABLE `feedback`.`ipintel` +ALTER TABLE `ipintel` ADD INDEX `idx_ipintel` (`ip` ASC, `intel` ASC, `date` ASC); -ALTER TABLE `feedback`.`library` +ALTER TABLE `library` ADD INDEX `idx_lib_id_del` (`id` ASC, `deleted` ASC) , ADD INDEX `idx_lib_del_title` (`deleted` ASC, `title` ASC) , ADD INDEX `idx_lib_search` (`deleted` ASC, `author` ASC, `title` ASC, `category` ASC); -ALTER TABLE `feedback`.`messages` +ALTER TABLE `messages` ADD INDEX `idx_msg_ckey_time` (`targetckey` ASC, `timestamp` ASC) , ADD INDEX `idx_msg_type_ckeys_time` (`type` ASC, `targetckey` ASC, `adminckey` ASC, `timestamp` ASC) , ADD INDEX `idx_msg_type_ckey_time_odr` (`type` ASC, `targetckey` ASC, `timestamp` ASC); -ALTER TABLE `feedback`.`player` +ALTER TABLE `player` ADD INDEX `idx_player_cid_ckey` (`computerid` ASC, `ckey` ASC) , ADD INDEX `idx_player_ip_ckey` (`ip` ASC, `ckey` ASC); -ALTER TABLE `feedback`.`poll_option` +ALTER TABLE `poll_option` ADD INDEX `idx_pop_pollid` (`pollid` ASC); -ALTER TABLE `feedback`.`poll_question` +ALTER TABLE `poll_question` ADD INDEX `idx_pquest_question_time_ckey` (`question` ASC, `starttime` ASC, `endtime` ASC, `createdby_ckey` ASC, `createdby_ip` ASC) , ADD INDEX `idx_pquest_time_admin` (`starttime` ASC, `endtime` ASC, `adminonly` ASC) , ADD INDEX `idx_pquest_id_time_type_admin` (`id` ASC, `starttime` ASC, `endtime` ASC, `polltype` ASC, `adminonly` ASC); -ALTER TABLE `feedback`.`poll_vote` +ALTER TABLE `poll_vote` ADD INDEX `idx_pvote_pollid_ckey` (`pollid` ASC, `ckey` ASC) , ADD INDEX `idx_pvote_optionid_ckey` (`optionid` ASC, `ckey` ASC); -ALTER TABLE `feedback`.`poll_textreply` +ALTER TABLE `poll_textreply` ADD INDEX `idx_ptext_pollid_ckey` (`pollid` ASC, `ckey` ASC); diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index 39717cc449dd4..c5ed1670ae951 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -1,6 +1,3 @@ -CREATE DATABASE IF NOT EXISTS `feedback` /*!40100 DEFAULT CHARACTER SET latin1 */; -USE `feedback`; - /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 3ccac32bd94b2..13d192785d6dc 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -1,6 +1,3 @@ -CREATE DATABASE IF NOT EXISTS `feedback` /*!40100 DEFAULT CHARACTER SET latin1 */; -USE `feedback`; - /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;