2
votes

This is similar to the question Rails Migration: indexes on a renamed table, only that I'm now using Elixir/Phoenix/Ecto.

I just renamed a table, but I just realized that, it seems the indices are still kept with their old names and are causing problems. Should I follow the procedures used for Rails 3, i.e. first drop the old indices before renaming the table, and then re-add the indices with create?

1
Yea, you need to drop the older ones, or you can keep them as it is and create the new ones. As the indices now have been orphaned after changing the table names. - Zubair Nabi
Downvoter: Care to explain? - xji

1 Answers

4
votes

I just worked through the same scenario but couldn't find any examples online of what it actually looks like in an Ecto migration to drop and recreate the constraints and indexes in the renamed table. I eventually figured it out and thought I would share what I did here in the hope that it helps someone out in the future: https://gist.github.com/wosephjeber/42472d6522d03161d710d5adb3dc3534

I'm by no means an Ecto expert, so there may be a better way, but this worked for me. I'm on Ecto 3.0 for what it's worth.