Does renameColumn also rename index as well?

If I have a column named column01 that is indexed, and I submit a changeset to rename the column to column02 with renameColumn liquibase command, will the name change also occur in the index or will I need to drop and recreate the index?

Hi @tremmie!

Would you mind posting your changeset so I could verify. Also, what DB platform are you using?

If you are just using sqldirect or equivalent, liquibase is just running the sql you provide it. So, it would depend on the platform, and how it would respond.

Thanks,

Ronak

@tremmie I will try this but as far as I know, the rename column SHOULD NOT update the index name as Index is an independent entity.
what DBMS are you working with ? oracle , postgresql ?

I will try it and see if what think is infact correct.

@ronak Here is the changeset example:

  <changeSet id="ID-1001" author="itemuser">
    <renameColumn
            columnDataType="java.sql.Types.NVARCHAR(128)"
            newColumnName="NEW_ITEM_ID"
            oldColumnName="OLD_ITEM_ID"
            tableName="ITEMS"/>
  </changeSet>

@hope99 I ended up experimenting and trying it myself, and from what I could tell the index name was updated and no errors were found when the changesets were ran. I am working with a Microsoft SQL Server and was surprised to see that the column name was updated and when I queried for the list of indexes the index for the old column name seemed to be renamed as well.

The index metadata should change to reflect the column name change for sure , but not sure why Index Name will be updated.

I tried in postgresql, updated column name and the index name was not updated . Index meta data was updated to point to new column name.

1 Like

@tremmie,

I think this is expected behavior on the mysql side. Here is a note I got from @costinmoraru:

Foreign key constraint names that point to the renamed table are automatically updated unless there is a conflict, in which case the statement fails with an error. A conflict occurs if the renamed constraint name already exists. In such cases, you must drop and re-create the foreign keys for them to function properly.

https://dev.mysql.com/doc/refman/5.7/en/rename-table.html
official mysql doc

Does that help resolve the issue @tremmie?

(thanks also to @hope99 for moving the issue forward too :slight_smile:

-Ronak

1 Like

Yes, thank you for the replies all! @ronak @hope99

1 Like