LendingHome / zero_downtime_migrations

Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
MIT License
561 stars 27 forks source link

Enforce column type when removing column #32

Open petestreet opened 6 years ago

petestreet commented 6 years ago

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.