class ColumnDropper def self.drop(table:, after_migration:, columns:, delay: nil, on_drop: nil) raise ArgumentError.new("Invalid table name passed to drop #{table}") if table =~ /[^a-z0-9_]/i columns.each do |column| raise ArgumentError.new("Invalid column name passed to drop #{column}") if column =~ /[^a-z0-9_]/i end delay ||= Rails.env.production? ? 60 : 0 sql = < 0 on_drop&.call columns.each do |column| # safe cause it is protected on method entry, can not be passed in params ActiveRecord::Base.exec_sql("ALTER TABLE #{table} DROP COLUMN IF EXISTS #{column}") end end end end