summaryrefslogtreecommitdiff
path: root/sql-files/upgrades/2013-11-18--08-23.sql
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-11-18 09:29:40 +0100
committerHaru <haru@dotalux.com>2013-11-18 09:29:40 +0100
commit4655f6611b14fca90ed38b021bf6a365cbfb335a (patch)
treef70c9f2392b7e8d2a95c2be4d99d8f8e0aa93375 /sql-files/upgrades/2013-11-18--08-23.sql
parent3e9758706ecf80d7656daefb546c80bf6b549967 (diff)
downloadhercules-4655f6611b14fca90ed38b021bf6a365cbfb335a.tar.gz
hercules-4655f6611b14fca90ed38b021bf6a365cbfb335a.tar.bz2
hercules-4655f6611b14fca90ed38b021bf6a365cbfb335a.tar.xz
hercules-4655f6611b14fca90ed38b021bf6a365cbfb335a.zip
Follow-up to 1f5161a2bd3c7934373146d8cac3c131536758ba
- Added explicit column names in the item_db query, to ensure it will throw a SQL error in case some are missing, rahter than silently failing and returning incorrect data. - Added sql upgrade file to add the bindonequip column to the item_db2 table for those who have it. - As with all the item_db2 upgrade scripts, you need at least MySQL 5.0 in order to run it. If your version is not compatible, or if the script fails for any reason, manual upgrade instructions are provided within the script. - Special thanks to Mumbles. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'sql-files/upgrades/2013-11-18--08-23.sql')
-rw-r--r--sql-files/upgrades/2013-11-18--08-23.sql65
1 files changed, 65 insertions, 0 deletions
diff --git a/sql-files/upgrades/2013-11-18--08-23.sql b/sql-files/upgrades/2013-11-18--08-23.sql
new file mode 100644
index 000000000..d5da5fd95
--- /dev/null
+++ b/sql-files/upgrades/2013-11-18--08-23.sql
@@ -0,0 +1,65 @@
+#1384763034
+
+-- Note: If you're running a MySQL version earlier than 5.0 (or if this scripts fails for you for any reason)
+-- you'll need to run the following queries manually:
+--
+-- [ Both Pre-Renewal and Renewal ]
+-- ALTER TABLE item_db2 ADD COLUMN `bindonequip` tinyint(1) unsigned DEFAULT NULL AFTER `view`;
+-- INSERT INTO `sql_updates` (`timestamp`) VALUES (1384763034);
+--
+-- [ End ]
+-- What follows is the automated script that does all of the above.
+
+DELIMITER $$
+
+DROP PROCEDURE IF EXISTS alter_if_not_exists $$
+DROP PROCEDURE IF EXISTS alter_if_exists $$
+
+CREATE PROCEDURE alter_if_not_exists(my_table TINYTEXT, my_column TINYTEXT, my_command TINYTEXT, my_predicate TEXT)
+BEGIN
+ set @dbname = DATABASE();
+ IF EXISTS (
+ SELECT * FROM information_schema.TABLES
+ WHERE TABLE_SCHEMA = @dbname
+ AND TABLE_NAME = my_table
+ ) AND NOT EXISTS (
+ SELECT * FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA = @dbname
+ AND TABLE_NAME = my_table
+ AND COLUMN_NAME = my_column
+ )
+ THEN
+ SET @q = CONCAT('ALTER TABLE ', @dbname, '.', my_table, ' ',
+ my_command, ' `', my_column, '` ', my_predicate);
+ PREPARE STMT FROM @q;
+ EXECUTE STMT;
+ END IF;
+
+END $$
+
+CREATE PROCEDURE alter_if_exists(my_table TINYTEXT, my_column TINYTEXT, my_command TINYTEXT, my_predicate TEXT)
+BEGIN
+ set @dbname = DATABASE();
+ IF EXISTS (
+ SELECT * FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA = @dbname
+ AND TABLE_NAME = my_table
+ AND COLUMN_NAME = my_column
+ )
+ THEN
+ SET @q = CONCAT('ALTER TABLE ', @dbname, '.', my_table, ' ',
+ my_command, ' `', my_column, '` ', my_predicate);
+ PREPARE STMT FROM @q;
+ EXECUTE STMT;
+ END IF;
+
+END $$
+
+CALL alter_if_not_exists('item_db2', 'bindonequip', 'ADD COLUMN', 'tinyint(1) unsigned DEFAULT NULL AFTER `view`') $$
+
+DROP PROCEDURE IF EXISTS alter_if_not_exists $$
+DROP PROCEDURE IF EXISTS alter_if_exists $$
+
+DELIMITER ';'
+
+INSERT INTO `sql_updates` (`timestamp`) VALUES (1384763034);