Created
July 17, 2013 15:34
-
-
Save thaniaclair/6021700 to your computer and use it in GitHub Desktop.
AddColumnUnlessExists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop procedure if exists AddColumnUnlessExists; | |
delimiter '//' | |
create procedure AddColumnUnlessExists( | |
IN dbName tinytext, | |
IN tableName tinytext, | |
IN ddl text) | |
begin | |
IF NOT EXISTS (SELECT * FROM information_schema.COLUMNS | |
WHERE column_name=fieldName | |
and table_name=tableName | |
and table_schema=dbName) | |
THEN | |
prepare stmt from ddl; | |
execute stmt; | |
END IF; | |
end; | |
// | |
delimiter ';' | |
call AddColumnUnlessExists('goeuro', 'seo_data', 'ALTER TABLE goeuro.seo_data ADD json_compressed_data BLOB NULL DEFAULT NULL AFTER json_data'); | |
call AddColumnUnlessExists('goeuro', 'seo_data', 'ALTER TABLE goeuro.seo_data CHANGE json_data json_data TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment