Skip to content

Support for adding a column if it doesn't exist #331

@ScottPierce

Description

@ScottPierce

Dialect

MySQL

Failing SQL

SELECT count(*) INTO @EXIST
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'mydatabase'
  AND COLUMN_NAME = 'mycolumn'
  AND TABLE_NAME = 'mytable' LIMIT 1;

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions