def add_migrations_for_table_to_buffer(table_info)
      @connection ||= ActiveRecord::Base.connection
      @types      ||= @connection.native_database_types

      column_specs = []
      @connection.columns(table_info.table_name).each do |column|
        next unless column.name.to_s.in? table_info.unused_attributes
        column_specs << column_spec_for(column)
      end

      quoted_table_name  = "\"#{table_info.table_name}\""
      column_specs.each do |colspec|
        down_syntax = [quoted_table_name, colspec[:name], ":#{colspec[:type]}", colspec[:options].presence].compact.join(', ')
        @migration_buffer << "    #  remove_column #{down_syntax}\n"
      end
    end
def add_migrations_for_table_to_buffer(table_info)
      @connection ||= ActiveRecord::Base.connection
      @types      ||= @connection.native_database_types

      column_specs = []
      @connection.columns(table_info.table_name).each do |column|
        next unless column.name.to_s.in? table_info.unused_attributes
        column_specs << column_spec_for(column)
      end

      quoted_table_name  = "\"#{table_info.table_name}\""
      column_specs.each do |colspec|
        down_syntax = [quoted_table_name, colspec[:name], ":#{colspec[:type]}", colspec[:options].presence].compact.join(', ')
        @migration_buffer << "    #  remove_column #{down_syntax}\n"
      end
    end
This is a modified version of the ActiveRecord::SchemaDumper#table method.
 Unfortunately, Rails generators cannot accept multiple tables in a single RemoveXXXFromXXX
 migration (maybe I should submit a PR to Rails?)
 ActiveRecord::SchemaDumper cannot be reused for this case, so I had to extract it.