From 997e61a36916bfab68bd3a3ff92fbef79051bb53 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 17 Sep 2022 18:50:13 +0100 Subject: [PATCH] Enforce charset, collation & engine on MySQL tables --- .../database/migrator/mysql_migrator.sql | 2 +- .../main/resources/database/mysql_schema.sql | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/src/main/resources/database/migrator/mysql_migrator.sql b/common/src/main/resources/database/migrator/mysql_migrator.sql index ab432f63..c0c7f245 100644 --- a/common/src/main/resources/database/migrator/mysql_migrator.sql +++ b/common/src/main/resources/database/migrator/mysql_migrator.sql @@ -64,7 +64,7 @@ FROM `%source_database%`.`%source_warps_table%` AS `%source_warps_table%` INNER JOIN `%target_saved_positions%` ON `%source_warps_table%`.`location_id` = `%target_saved_positions%`.`position_id`; --- Rename old tables +# Rename old tables ALTER TABLE `%source_database%`.`%source_positions_table%` RENAME TO `old_%source_positions_table%`; ALTER TABLE `%source_database%`.`%source_users_table%` RENAME TO `old_%source_users_table%`; ALTER TABLE `%source_database%`.`%source_homes_table%` RENAME TO `old_%source_homes_table%`; diff --git a/common/src/main/resources/database/mysql_schema.sql b/common/src/main/resources/database/mysql_schema.sql index 002a2b51..318ef181 100644 --- a/common/src/main/resources/database/mysql_schema.sql +++ b/common/src/main/resources/database/mysql_schema.sql @@ -1,3 +1,9 @@ +# Set the storage engine +SET DEFAULT_STORAGE_ENGINE = INNODB; + +# Enable foreign key constraints +SET FOREIGN_KEY_CHECKS = 1; + # Create the positions table if it does not exist CREATE TABLE IF NOT EXISTS `%positions_table%` ( @@ -12,7 +18,8 @@ CREATE TABLE IF NOT EXISTS `%positions_table%` `server_name` varchar(255) NOT NULL, PRIMARY KEY (`id`) -); +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; # Create the players table if it does not exist CREATE TABLE IF NOT EXISTS `%players_table%` @@ -30,7 +37,8 @@ CREATE TABLE IF NOT EXISTS `%players_table%` FOREIGN KEY (`last_position`) REFERENCES `%positions_table%` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION, FOREIGN KEY (`offline_position`) REFERENCES `%positions_table%` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION, FOREIGN KEY (`respawn_position`) REFERENCES `%positions_table%` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION -); +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; # Create the current cross-server teleports table if it does not exist CREATE TABLE IF NOT EXISTS `%teleports_table%` @@ -42,7 +50,8 @@ CREATE TABLE IF NOT EXISTS `%teleports_table%` PRIMARY KEY (`player_uuid`), FOREIGN KEY (`player_uuid`) REFERENCES `%players_table%` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`destination_id`) REFERENCES `%positions_table%` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION -); +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; # Create the saved positions table if it does not exist CREATE TABLE IF NOT EXISTS `%saved_positions_table%` @@ -56,7 +65,8 @@ CREATE TABLE IF NOT EXISTS `%saved_positions_table%` PRIMARY KEY (`id`), FOREIGN KEY (`position_id`) REFERENCES `%positions_table%` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION -); +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; # Create the homes table if it does not exist CREATE TABLE IF NOT EXISTS `%homes_table%` @@ -69,7 +79,8 @@ CREATE TABLE IF NOT EXISTS `%homes_table%` PRIMARY KEY (`uuid`), FOREIGN KEY (`owner_uuid`) REFERENCES `%players_table%` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`saved_position_id`) REFERENCES `%saved_positions_table%` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION -); +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; # Create the warps table if it does not exist CREATE TABLE IF NOT EXISTS `%warps_table%` @@ -79,4 +90,5 @@ CREATE TABLE IF NOT EXISTS `%warps_table%` PRIMARY KEY (`uuid`), FOREIGN KEY (`saved_position_id`) REFERENCES `%saved_positions_table%` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION -); \ No newline at end of file +) CHARACTER SET utf8 + COLLATE utf8_unicode_ci; \ No newline at end of file