Rename migration file and module

Hi,

I recently created a migration using ecto which looked something like this:

defmodule MyApp.Repo.Migrations.AddDateOfBirthToUsers do
  use Ecto.Migration

  def change do
    alter table("users") do
      add(:date_of_birth, :date,
        null: true,
        comment:
          "Send the user flowers on birthday."
      )
    end
  end
end

The file was named 20201208164822_add_date_of_birth_to_users.exs
The file went through some code reviews and eventually the name of the field was changed to first_day_on_earth. The code was finally merged and deployed using CI/CD pipelines and is in production now.
However, I then realized that I could have changed the file name and the auto generated module name to better reflect the code changes in the review process.

My question is - how do I change or update the module name and the name of the migration file? What will be the cleanest way to to do this? Does it even matter?

FWIW, only the timestamp (20201208164822) part of the name is tracked in schema_migrations - changing the module name shouldn’t have any effect as far as I know.

1 Like