luckyframework/avram

[Improvement] Better usage when use `make_required` `make_optional` and `remove` on the migration.

Opened this issue · 0 comments

Assume my db table foo, have two column, column1, column2

this is a common use case where the data from column1 is migrated to column2 and then remove column column1, and then make column2 required.

so, migration like this:

class Foo::V20240427102500 < Avram::Migrator::Migration::V1
  def migrate
      # Do data migrating from column1 to column2 ...

    make_required table_for(Foo), :column2
    alter table_for(Foo) do
      remove :column1
    end
  end

  def rollback
  end
end

It works!, but i consider it is better if we can use like following:

 alert table_for(Foo) do
   make_required :column2
   remove :column1
 end

Or

make_required table_for(Foo), :column2
remove table_for(Foo), :column1

Thanks


EDIT: okay, probably write migrate data and delete old column in same migration file is not good idea, but anyway, same usage is better.