Renaming Postgres index, FK, PK, sequences

Hi everyone,

I wanted to share some code that might be useful for those dealing with table renaming in Ecto migrations. While using Ecto.Migration.rename/2 is straightforward, we’ve encountered an issue: the associated indexes, primary keys, and foreign keys retain their original naming conventions, which can lead to confusion.

To address this, our team developed some helper functions that streamline the renaming process and ensure that all related database objects are renamed consistently.

A bonus is that you get rollback for free.

Feel free to leave any comments or suggestions!
Hope this helps!

6 Likes

This is great, thank you! I’ve faced this several times recently and it’s a slog. It feels like this could be in Ecto. Are there some edge cases that would make this a maintenance burden?

1 Like

Thanks!
There may be edge cases, but I still haven’t spotted any :man_shrugging: