zero_downtime_migrations icon indicating copy to clipboard operation
zero_downtime_migrations copied to clipboard

Enforce column type when removing column

Open petestreet opened this issue 7 years ago • 0 comments

Adds a new validation that warns when a remove_column migration is run without providing a column type.

Bad (rails raises this error when attempting a rollback):

class RemovePublishedFromPosts < ActiveRecord::Migration
  def change
    remove_column :posts, :published
  end
end

Good:

class RemovePublishedFromPosts < ActiveRecord::Migration
  def change
    remove_column :posts, :published, :boolean
  end
end

Note that this branch only checks for database-agnostic types listed in the Rails API docs. I'm open to also including types specific to Postgres, MySQL, and SQLite, so that users of the most common DBs don't get extraneous errors from this gem. The guides have an official page for Postgres types -- I don't see a corresponding one for MySQL or SQLite, but can try to hunt down an official types list for each of those if you think that's a reasonable next step.

petestreet avatar Oct 06 '18 22:10 petestreet