Created
July 15, 2013 17:11
-
-
Save jdmullin/6001655 to your computer and use it in GitHub Desktop.
Older pattern for idempotent alter scripts
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
SELECT count(*) | |
INTO @exist | |
FROM information_schema.columns | |
WHERE table_schema = 'databaseName' | |
and COLUMN_NAME = 'columnName' | |
AND table_name = 'tableName'; | |
set @query = IF(@exist <= 0, | |
'alter table whatever', | |
'select \'Column already exists\' status'); | |
prepare stmt from @query; | |
EXECUTE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment