You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECTcount(*) INTO @EXIST
FROMINFORMATION_SCHEMA.COLUMNSWHERE TABLE_SCHEMA ='mydatabase'AND COLUMN_NAME ='mycolumn'AND TABLE_NAME ='mytable'LIMIT1;
SET @query = IF (@exist <=0, 'ALTER TABLE mydatabase.`mytable` ADD COLUMN `mycolumn` MEDIUMTEXT NULL',
'select \' COLUMN EXISTS\' status');
PREPARE stmt FROM @query;
EXECUTE stmt;
Description
I'm trying to write my migration files in a repeatable manner (So I don't have to create a new migration version EVERY time I need to make a change), but I can't seem to do this when altering a table when adding a column or adding an index. I don't necessarily need to do it in the above way, but I do think this should be supported some way.
The text was updated successfully, but these errors were encountered:
IF NOT EXISTS( SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'tableName'
AND table_schema = 'database_name'
AND column_name = 'columnName') THEN
ALTER TABLE Example ADD COLUMN location VARCHAR(50) NULL;
END IF;
Dialect
MySQL
Failing SQL
Description
I'm trying to write my migration files in a repeatable manner (So I don't have to create a new migration version EVERY time I need to make a change), but I can't seem to do this when altering a table when adding a column or adding an index. I don't necessarily need to do it in the above way, but I do think this should be supported some way.
The text was updated successfully, but these errors were encountered: