Search code examples
intellij-ideadatabase-migrationflyway

Intellij flyway migration rename column


I would like to carry out my database migration with flyway. This works in most cases, but the renaming of columns does not yet work as expected. To create the migration scripts, I use the built-in Create flyway versioned migration function of Intellij. When I rename a column, the following script is generated:

ALTER TABLE demo
    ADD last_name VARCHAR(255);

ALTER TABLE demo
    DROP COLUMN surname;

But I expect something along the lines of:

ALTER TABLE demo ALTER COLUMN surname RENAME TO last_name;

Is there a way to generate this automatically, or do I have to intervene manually in case of renaming?

I tried to use the @Column(name = “last_name”) annotation, but with this I can only change the name of the variable and not the name of the column


Solution

  • Yes, such way exists. The migration cannot process it automatically, but you can configure that. On the preview screen you need to select "Add Column" item and select "Merge with dropColumn" on the top of the preview - in this case two changes will be merged into the "Rename" one.

    Feature screenshot