Removing a Column

Active Record caches database columns at runtime, so when we drop a column, it will cause exceptions until app reboots.

When ActiveRecord during boot, it loads the cached schema cache file and try to define attributes for your model, but when we remove a column, it will try to define an attribute not exist in the database and hit an error.

So when removing a column, e.g. removing events.payload.

class Events < ApplicationRecord
  self.ignored_columns = ["payload"]
end

Remove all application usage of event.payload.

Deploy.

class RemoveSomeColumnFromUsers < ActiveRecord::Migration[7.0]
  def change
    remove_column :events, :payload
  end
end