Artur-Sulej / excellent_migrations

An Elixir tool for checking safety of database migrations.
MIT License
232 stars 25 forks source link

Feature Request: Reversible migrations #9

Open axelson opened 2 years ago

axelson commented 2 years ago

It would be great if excellent_migrations could enforce that a migration is reversible as a check.

Artur-Sulej commented 2 years ago

That's a nice idea.

I guess it could be implemented by checking if def down or def change is implemented. def change may not be reversible (e.g. if execute is used) but sometimes that may not be easy to detect.

Artur-Sulej commented 2 years ago

@axelson I like your idea. Would you like to issue a pull request with the change?

axelson commented 2 years ago

Thank you! I likely wouldn't get this anytime soon. So it's probably best if you or someone else tackles it.

Stratus3D commented 2 weeks ago

I would love to have this feature as well, and I may have some time to implement this.

How should checks for the down and change callbacks work?

For example, given this migration:

defmodule MyMigration do
  use Ecto.Migration

  def change do
    create table(:mytable) do
      add(:some_field, :uuid, null: false)

      timestamps()
    end
  end
end

Ecto migrations will generate rollback code that will drop mytable. If I'd created this same migration but with up and down callbacks excellent migrations would complain about the drop table in the down migration. What is desired? Destructive rollbacks or only safe rollbacks?