diff --git a/code/modules/library/computers/base.dm b/code/modules/library/computers/base.dm index 5f4e7e84384..72893538aba 100644 --- a/code/modules/library/computers/base.dm +++ b/code/modules/library/computers/base.dm @@ -36,7 +36,6 @@ return text2num(_query.item[1]) return 0 - /obj/machinery/computer/library/proc/get_pagelist() var/pagelist = "
" var/start = max(0,page_num-3) diff --git a/code/modules/library/lib_machines.dm b/code/modules/library/lib_machines.dm index f71baf1f43d..96c31f28b20 100644 --- a/code/modules/library/lib_machines.dm +++ b/code/modules/library/lib_machines.dm @@ -76,7 +76,8 @@ CB.author = B.author CB.programmatic=1 CB.path=typepath - CB.id = "M"+newid++ + CB.id = "M[newid]" + newid++ cached_books[CB.id]=CB @@ -192,7 +193,7 @@ var/global/list/library_section_names = list("Any", "Fiction", "Non-Fiction", "A src.visible_message("[src] whirs as it prints and binds a new book.") var/obj/item/weapon/book/b = new(src.loc) b.dat = O:info - b.name = "Print Job #" + "[rand(100, 999)]" + b.name = "Print Job #[rand(100, 999)]" b.icon_state = "book[rand(1,7)]" del(O) else diff --git a/code/modules/migrations/SS13/001-create-erro-tables.dm b/code/modules/migrations/SS13/001-create-erro-tables.dm index cc874e53df6..f805bbde178 100644 --- a/code/modules/migrations/SS13/001-create-erro-tables.dm +++ b/code/modules/migrations/SS13/001-create-erro-tables.dm @@ -11,8 +11,11 @@ CREATE TABLE IF NOT EXISTS `erro_admin` ( `level` int(2) NOT NULL DEFAULT '0', `flags` int(16) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_admin_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` datetime NOT NULL, @@ -20,8 +23,11 @@ CREATE TABLE IF NOT EXISTS `erro_admin_log` ( `adminip` varchar(18) NOT NULL, `log` text NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_ban` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bantime` datetime NOT NULL, @@ -47,8 +53,11 @@ CREATE TABLE IF NOT EXISTS `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;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_feedback` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time` datetime NOT NULL, @@ -57,8 +66,11 @@ CREATE TABLE IF NOT EXISTS `erro_feedback` ( `var_value` int(16) DEFAULT NULL, `details` text, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; +) ENGINE=MyISAM DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_player` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ckey` varchar(32) NOT NULL, @@ -69,8 +81,11 @@ CREATE TABLE IF NOT EXISTS `erro_player` ( `lastadminrank` varchar(32) NOT NULL DEFAULT 'Player', PRIMARY KEY (`id`), UNIQUE KEY `ckey` (`ckey`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_poll_option` ( `id` int(11) NOT NULL AUTO_INCREMENT, `pollid` int(11) NOT NULL, @@ -82,8 +97,11 @@ CREATE TABLE IF NOT EXISTS `erro_poll_option` ( `descmid` varchar(32) DEFAULT NULL, `descmax` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_poll_question` ( `id` int(11) NOT NULL AUTO_INCREMENT, `polltype` varchar(16) NOT NULL DEFAULT 'OPTION', @@ -92,8 +110,11 @@ CREATE TABLE IF NOT EXISTS `erro_poll_question` ( `question` varchar(255) NOT NULL, `adminonly` tinyint(1) DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_poll_textreply` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` datetime NOT NULL, @@ -103,8 +124,11 @@ CREATE TABLE IF NOT EXISTS `erro_poll_textreply` ( `replytext` text NOT NULL, `adminrank` varchar(32) NOT NULL DEFAULT 'Player', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_poll_vote` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` datetime NOT NULL, @@ -115,19 +139,22 @@ CREATE TABLE IF NOT EXISTS `erro_poll_vote` ( `adminrank` varchar(32) NOT NULL, `rating` int(2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `erro_privacy` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` datetime NOT NULL, `ckey` varchar(32) NOT NULL, `option` varchar(128) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; +) ENGINE=InnoDB DEFAULT CHARSET=latin1;"} + if(!execute(sql)) + return FALSE --- ----------------------------------------------------- --- Non-erro tables. --- ----------------------------------------------------- + sql={" CREATE TABLE IF NOT EXISTS `death` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `pod` TEXT NOT NULL COMMENT 'Place of death' , @@ -146,8 +173,11 @@ CREATE TABLE IF NOT EXISTS `death` ( `oxyloss` INT(11) NOT NULL , PRIMARY KEY (`id`) ) ENGINE = MyISAM -DEFAULT CHARACTER SET = latin1; +DEFAULT CHARACTER SET = latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `karma` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `spendername` TEXT NOT NULL , @@ -161,16 +191,22 @@ CREATE TABLE IF NOT EXISTS `karma` ( `time` DATETIME NOT NULL , PRIMARY KEY (`id`) ) ENGINE = MyISAM -DEFAULT CHARACTER SET = latin1; +DEFAULT CHARACTER SET = latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `karmatotals` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `byondkey` TEXT NOT NULL , `karma` INT(11) NOT NULL , PRIMARY KEY (`id`) ) ENGINE = MyISAM -DEFAULT CHARACTER SET = latin1; +DEFAULT CHARACTER SET = latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `library` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `author` TEXT NOT NULL , @@ -179,8 +215,11 @@ CREATE TABLE IF NOT EXISTS `library` ( `category` TEXT NOT NULL , PRIMARY KEY (`id`) ) ENGINE = MyISAM -DEFAULT CHARACTER SET = latin1; +DEFAULT CHARACTER SET = latin1;"} + if(!execute(sql)) + return FALSE + sql={" CREATE TABLE IF NOT EXISTS `population` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `playercount` INT(11) NULL DEFAULT NULL , @@ -188,6 +227,5 @@ CREATE TABLE IF NOT EXISTS `population` ( `time` DATETIME NOT NULL , PRIMARY KEY (`id`) ) ENGINE = MyISAM -DEFAULT CHARACTER SET = latin1; -"} - execute(sql) \ No newline at end of file +DEFAULT CHARACTER SET = latin1;"} + return execute(sql) \ No newline at end of file diff --git a/code/modules/migrations/SS13/002-create-session-table.dm b/code/modules/migrations/SS13/002-create-session-table.dm index faf453510f9..43b9c64b79b 100644 --- a/code/modules/migrations/SS13/002-create-session-table.dm +++ b/code/modules/migrations/SS13/002-create-session-table.dm @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS admin_sessions ( `expires` DATETIME ); "} - execute(sql) + return execute(sql) /datum/migration/ss13/_002/down() - execute("DROP TABLE IF EXISTS admin_sessions;"); + return execute("DROP TABLE IF EXISTS admin_sessions;"); diff --git a/code/modules/migrations/SS13/003-add-multi-option-polls.dm b/code/modules/migrations/SS13/003-add-multi-option-polls.dm index e835829ba5b..6577a8c1c50 100644 --- a/code/modules/migrations/SS13/003-add-multi-option-polls.dm +++ b/code/modules/migrations/SS13/003-add-multi-option-polls.dm @@ -4,12 +4,14 @@ /datum/migration/ss13/_003/up() if(!hasColumn("erro_poll_question","multiplechoiceoptions")) - execute("ALTER TABLE erro_poll_question ADD COLUMN `multiplechoiceoptions` int(2) DEFAULT NULL;") + return execute("ALTER TABLE erro_poll_question ADD COLUMN `multiplechoiceoptions` int(2) DEFAULT NULL;") else warning("multiplechoiceoptions column exists. Skipping addition.") + return TRUE /datum/migration/ss13/_003/down() if(hasColumn("erro_poll_question","multiplechoiceoptions")) - execute("ALTER TABLE erro_poll_question DROP COLUMN `multiplechoiceoptions`;") + return execute("ALTER TABLE erro_poll_question DROP COLUMN `multiplechoiceoptions`;") else - warning("multiplechoiceoptions column does not exist. Skipping drop.") \ No newline at end of file + warning("multiplechoiceoptions column does not exist. Skipping drop.") + return TRUE \ No newline at end of file diff --git a/code/modules/migrations/SS13/004-add-ip-to-sessions.dm b/code/modules/migrations/SS13/004-add-ip-to-sessions.dm index 5f4e4e6004c..6e23fb179da 100644 --- a/code/modules/migrations/SS13/004-add-ip-to-sessions.dm +++ b/code/modules/migrations/SS13/004-add-ip-to-sessions.dm @@ -4,12 +4,14 @@ /datum/migration/ss13/_004/up() if(!hasColumn("admin_sessions","IP")) - execute("ALTER TABLE admin_sessions ADD COLUMN `IP` VARCHAR(255) DEFAULT NULL;"); + return execute("ALTER TABLE admin_sessions ADD COLUMN `IP` VARCHAR(255) DEFAULT NULL;"); else warning("IP column exists. Skipping addition.") + return TRUE /datum/migration/ss13/_004/down() if(hasColumn("admin_sessions","IP")) - execute("ALTER TABLE admin_sessions DROP COLUMN `IP`;"); + return execute("ALTER TABLE admin_sessions DROP COLUMN `IP`;"); else - warning("IP column does not exist. Skipping drop.") \ No newline at end of file + warning("IP column does not exist. Skipping drop.") + return TRUE \ No newline at end of file diff --git a/code/modules/migrations/SS13/005-modernize-library.dm b/code/modules/migrations/SS13/005-modernize-library.dm index 40f2c083524..54b23fe7730 100644 --- a/code/modules/migrations/SS13/005-modernize-library.dm +++ b/code/modules/migrations/SS13/005-modernize-library.dm @@ -4,12 +4,14 @@ /datum/migration/ss13/_005/up() if(!hasColumn("library","ckey")) - execute("ALTER TABLE library ADD COLUMN `ckey` VARCHAR(32) NOT NULL DEFAULT '\[Unknown\]';"); + return execute("ALTER TABLE library ADD COLUMN `ckey` VARCHAR(32) NULL;"); // Permit nulls, we interpret these as old values. else warning("ckey column exists. Skipping addition.") + return TRUE /datum/migration/ss13/_005/down() if(hasColumn("library","ckey")) - execute("ALTER TABLE library DROP COLUMN `ckey`;"); + return execute("ALTER TABLE library DROP COLUMN `ckey`;"); else - warning("ckey column does not exist. Skipping drop.") \ No newline at end of file + warning("ckey column does not exist. Skipping drop.") + return TRUE \ No newline at end of file diff --git a/code/modules/migrations/migration.dm b/code/modules/migrations/migration.dm index ffab7c0af21..04fc316a2dc 100644 --- a/code/modules/migrations/migration.dm +++ b/code/modules/migrations/migration.dm @@ -13,15 +13,18 @@ /datum/migration/proc/up() // Make your changes here. - return + return TRUE /datum/migration/proc/down() // Undo your changes here (for rollbacks) - return + return TRUE // Helpers /datum/migration/proc/query(var/sql) - var/DBQuery/query = execute(sql) + var/DBQuery/query = db.NewQuery(sql) + if(!query.Execute()) + world.log << "Error in [package]#[id]: [query.ErrorMsg()]" + return FALSE var/list/rows=list() while(query.NextRow()) @@ -29,7 +32,10 @@ return rows /datum/migration/proc/hasResult(var/sql) - var/DBQuery/query = execute(sql) + var/DBQuery/query = db.NewQuery(sql) + if(!query.Execute()) + world.log << "Error in [package]#[id]: [query.ErrorMsg()]" + return FALSE if (query.NextRow()) return TRUE @@ -37,8 +43,10 @@ /datum/migration/proc/execute(var/sql) var/DBQuery/query = db.NewQuery(sql) - query.Execute() - return query + if(!query.Execute()) + world.log << "Error in [package]#[id]: [query.ErrorMsg()]" + return FALSE + return TRUE /datum/migration/proc/hasTable(var/tableName) return hasResult("SHOW TABLES LIKE '[tableName]'") diff --git a/code/modules/migrations/migration_controller.dm b/code/modules/migrations/migration_controller.dm index 8b4a6acc743..409c7253356 100644 --- a/code/modules/migrations/migration_controller.dm +++ b/code/modules/migrations/migration_controller.dm @@ -21,7 +21,7 @@ var/global/datum/migration_controller/migration_controller = null if(!hasTable(TABLE_NAME)) var/tableSQL = {" -CREATE TABLE [TABLE_NAME] ( +CREATE TABLE IF NOT EXISTS [TABLE_NAME] ( pkgID VARCHAR(15) PRIMARY KEY, -- Implies NOT NULL version INT(11) NOT NULL ); @@ -31,6 +31,7 @@ CREATE TABLE [TABLE_NAME] ( Q.Close() Q = db.NewQuery("SELECT pkgID, version FROM [TABLE_NAME]") + Q.Execute() while(Q.NextRow()) db_states[Q.item[1]] = text2num(Q.item[2]) @@ -38,7 +39,7 @@ CREATE TABLE [TABLE_NAME] ( for(var/mtype in typesof(/datum/migration)-/datum/migration) var/datum/migration/M = new mtype() M.db = db - if(M.package == "") continue + if(M.package == "" || M.name == "") continue if(!(M.package in newpacks)) newpacks[M.package]=list() var/list/pack = newpacks[M.package] @@ -50,8 +51,9 @@ CREATE TABLE [TABLE_NAME] ( var/list/pack[prepack.len] for(var/datum/migration/M in newpacks[pkgID]) pack[M.id] = M + //world.log << "\[Migrations] [pkgID]#[M.id] = [M.type] - [M.name]" packages[pkgID]=pack - world.log << "Loaded [pack.len] DB migrations from package [pkgID]." + world.log << "\[Migrations] Loaded [pack.len] DB migrations from package [pkgID]." //VersionCheck() UpdateAll() @@ -64,12 +66,14 @@ CREATE TABLE [TABLE_NAME] ( /datum/migration_controller/proc/VersionCheck() for(var/pkgID in packages) + var/currentVersion = getCurrentVersion(pkgID) var/latestVersionAvail = 0 for(var/datum/migration/M in packages[pkgID]) if(M.id > latestVersionAvail) latestVersionAvail = M.id - if(latestVersionAvail > getCurrentVersion()) - world.log << "*** [pkgID] is behind [latestVersionAvail-db_states[pkgID]] versions!" + //world.log << "\[Migrations] Package [pkgID]: Current: [currentVersion], Avail: [latestVersionAvail]" + if(latestVersionAvail > currentVersion) + world.log << "\[Migrations] *** [pkgID] is behind [latestVersionAvail-currentVersion] versions!" /datum/migration_controller/proc/UpdateAll() for(var/pkgID in packages) @@ -88,16 +92,20 @@ CREATE TABLE [TABLE_NAME] ( for(var/datum/migration/M in packages[pkgID]) if(M.id > to_version) to_version = M.id - var/log_text = "Updating [pkgID] from [from_version] to [to_version]..." + if(from_version == to_version) + world.log << "\[Migrations] [pkgID] is up to date." + return + world.log << "\[Migrations] Updating [pkgID] from [from_version] to [to_version]..." for(var/datum/migration/M in package) if(M.id > from_version && M.id <= to_version) if(!M.up()) - world << "[log_text] FAIL
Failed to process migration [pkgID] #[M.id]!" + //world << "[log_text] FAIL
Failed to process migration [pkgID] #[M.id]!" world.log << "Failed to process migration [pkgID] #[M.id]" return FALSE else M.execute("REPLACE INTO [TABLE_NAME] (pkgID,version) VALUES ('[pkgID]',[M.id])") - world << "[log_text] OK" + world.log << "\[Migrations] Successfully applied [pkgID]#[M.id] ([M.name])" + world.log << "\[Migrations] Done!" return TRUE /datum/migration_controller/proc/query(var/sql)