diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 6e6bd7f7ca..a232d0028b 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -1,15 +1,66 @@ Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255. +<<<<<<< HEAD The latest database version is 4.1; The query to update the schema revision table is: INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 1); or INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 1); +======= +The latest database version is 4.4; The query to update the schema revision table is: + +INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 4); +or +INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 4); +>>>>>>> 37854a5... Splits up round table initialize, start, end and shutdown (#37665) In any query remember to add a prefix to the table names if you use one. ---------------------------------------------------- +<<<<<<< HEAD +======= +Version 4.4, 9 May 2018, by Jordie0608 +Modified table `round`, renaming column `start_datetime` to `initialize_datetime` and `end_datetime` to `shutdown_datetime` and adding columns to replace both under the same name in preparation for changes to TGS server initialization. + +ALTER TABLE `round` + ALTER `start_datetime` DROP DEFAULT; +ALTER TABLE `round` + CHANGE COLUMN `start_datetime` `initialize_datetime` DATETIME NOT NULL AFTER `id`, + ADD COLUMN `start_datetime` DATETIME NULL DEFAULT NULL AFTER `initialize_datetime`, + CHANGE COLUMN `end_datetime` `shutdown_datetime` DATETIME NULL DEFAULT NULL AFTER `start_datetime`, + ADD COLUMN `end_datetime` DATETIME NULL DEFAULT NULL AFTER `shutdown_datetime`; + +---------------------------------------------------- + +Version 4.3, 9 May 2018, by MrStonedOne +Added table `role_time_log` and triggers `role_timeTlogupdate`, `role_timeTloginsert` and `role_timeTlogdelete` to update it from changes to `role_time` + +CREATE TABLE `role_time_log` ( `id` BIGINT NOT NULL AUTO_INCREMENT , `ckey` VARCHAR(32) NOT NULL , `job` VARCHAR(128) NOT NULL , `delta` INT NOT NULL , `datetime` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`), INDEX (`ckey`), INDEX (`job`), INDEX (`datetime`)) ENGINE = InnoDB; + +DELIMITER +$$ +CREATE TRIGGER `role_timeTlogupdate` AFTER UPDATE ON `role_time` FOR EACH ROW BEGIN INSERT into role_time_log (ckey, job, delta) VALUES (NEW.CKEY, NEW.job, NEW.minutes-OLD.minutes); +END +$$ +CREATE TRIGGER `role_timeTloginsert` AFTER INSERT ON `role_time` FOR EACH ROW BEGIN INSERT into role_time_log (ckey, job, delta) VALUES (NEW.ckey, NEW.job, NEW.minutes); +END +$$ +CREATE TRIGGER `role_timeTlogdelete` AFTER DELETE ON `role_time` FOR EACH ROW BEGIN INSERT into role_time_log (ckey, job, delta) VALUES (OLD.ckey, OLD.job, 0-OLD.minutes); +END +$$ + +---------------------------------------------------- + +Version 4.2, 17 April 2018, by Jordie0608 +Modified table 'admin', adding the columns 'round_id' and 'target' +ALTER TABLE `admin_log` + ADD COLUMN `round_id` INT UNSIGNED NOT NULL AFTER `datetime`, + ADD COLUMN `target` VARCHAR(32) NOT NULL AFTER `operation`; + +---------------------------------------------------- + +>>>>>>> 37854a5... Splits up round table initialize, start, end and shutdown (#37665) Version 4.1, 3 February 2018, by Jordie0608 Modified tables 'admin', 'admin_log' and 'admin_rank', removing unnecessary columns and adding support for excluding rights flags from admin ranks. This change was made to enable use of sql-based admin loading. diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index ddd31a7e80..dc9a576377 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -397,7 +397,9 @@ DROP TABLE IF EXISTS `round`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `round` ( `id` INT(11) NOT NULL AUTO_INCREMENT, - `start_datetime` DATETIME NOT NULL, + `initialize_datetime` DATETIME NOT NULL, + `start_datetime` DATETIME NULL, + `shutdown_datetime` DATETIME NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 01e0ed150b..f34a084fbf 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -397,7 +397,9 @@ DROP TABLE IF EXISTS `SS13_round`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `SS13_round` ( `id` INT(11) NOT NULL AUTO_INCREMENT, - `start_datetime` DATETIME NOT NULL, + `initialize_datetime` DATETIME NOT NULL, + `start_datetime` DATETIME NULL, + `shutdown_datetime` DATETIME NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 2b5e42e339..6818b567d5 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -1,7 +1,11 @@ //Update this whenever the db schema changes //make sure you add an update to the schema_version stable in the db changelog #define DB_MAJOR_VERSION 4 +<<<<<<< HEAD #define DB_MINOR_VERSION 1 +======= +#define DB_MINOR_VERSION 4 +>>>>>>> 37854a5... Splits up round table initialize, start, end and shutdown (#37665) //Timing subsystem //Don't run if there is an identical unique timer active diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm index fcf5a5dd4a..b9db24e447 100644 --- a/code/__HELPERS/roundend.dm +++ b/code/__HELPERS/roundend.dm @@ -220,7 +220,7 @@ log_game("[i]s[total_antagonists[i]].") CHECK_TICK - + SSdbcore.SetRoundEnd() //Collects persistence features if(mode.allow_persistence_save) SSpersistence.CollectData() diff --git a/code/controllers/subsystem/dbcore.dm b/code/controllers/subsystem/dbcore.dm index 0609b78d99..b026f8ad6f 100644 --- a/code/controllers/subsystem/dbcore.dm +++ b/code/controllers/subsystem/dbcore.dm @@ -37,19 +37,18 @@ SUBSYSTEM_DEF(dbcore) message_admins("Database schema ([db_major].[db_minor]) doesn't match the latest schema version ([DB_MAJOR_VERSION].[DB_MINOR_VERSION]), this may lead to undefined behaviour or errors") if(2) message_admins("Could not get schema version from database") - + return ..() - + /datum/controller/subsystem/dbcore/Recover() _db_con = SSdbcore._db_con /datum/controller/subsystem/dbcore/Shutdown() //This is as close as we can get to the true round end before Disconnect() without changing where it's called, defeating the reason this is a subsystem if(SSdbcore.Connect()) - var/sql_station_name = sanitizeSQL(station_name()) - var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[sanitizeSQL(SSticker.mode_result)]', end_state = '[sanitizeSQL(SSticker.end_state)]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]") - query_round_end.Execute() + var/datum/DBQuery/query_round_shutdown = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET shutdown_datetime = Now(), end_state = '[sanitizeSQL(SSticker.end_state)]' WHERE id = [GLOB.round_id]") + query_round_shutdown.Execute() if(IsConnected()) Disconnect() @@ -107,13 +106,26 @@ SUBSYSTEM_DEF(dbcore) /datum/controller/subsystem/dbcore/proc/SetRoundID() if(CONFIG_GET(flag/sql_enabled)) if(SSdbcore.Connect()) - var/datum/DBQuery/query_round_start = SSdbcore.NewQuery("INSERT INTO [format_table_name("round")] (start_datetime, server_ip, server_port) VALUES (Now(), INET_ATON(IF('[world.internet_address]' LIKE '', '0', '[world.internet_address]')), '[world.port]')") - query_round_start.Execute() + var/datum/DBQuery/query_round_initialize = SSdbcore.NewQuery("INSERT INTO [format_table_name("round")] (initialize_datetime, server_ip, server_port) VALUES (Now(), INET_ATON(IF('[world.internet_address]' LIKE '', '0', '[world.internet_address]')), '[world.port]')") + query_round_initialize.Execute() var/datum/DBQuery/query_round_last_id = SSdbcore.NewQuery("SELECT LAST_INSERT_ID()") query_round_last_id.Execute() if(query_round_last_id.NextRow()) GLOB.round_id = query_round_last_id.item[1] +/datum/controller/subsystem/dbcore/proc/SetRoundStart() + if(CONFIG_GET(flag/sql_enabled)) + if(SSdbcore.Connect()) + var/datum/DBQuery/query_round_start = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET start_datetime = Now() WHERE id = [GLOB.round_id]") + query_round_start.Execute() + +/datum/controller/subsystem/dbcore/proc/SetRoundEnd() + if(CONFIG_GET(flag/sql_enabled)) + if(SSdbcore.Connect()) + var/sql_station_name = sanitizeSQL(station_name()) + var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[sanitizeSQL(SSticker.mode_result)]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]") + query_round_end.Execute() + /datum/controller/subsystem/dbcore/proc/Disconnect() failed_connections = 0 return _dm_db_close(_db_con) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 270970c61b..b44f335ffc 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -301,6 +301,7 @@ SUBSYSTEM_DEF(ticker) log_world("Game start took [(world.timeofday - init_start)/10]s") round_start_time = world.time + SSdbcore.SetRoundStart() to_chat(world, "Welcome to [station_name()], enjoy your stay!") SEND_SOUND(world, sound('sound/ai/welcome.ogg'))