How to check if a colum is present in table in rails migration

Solution 1:

  def self.up
    unless ActiveRecord::Base.connection.column_exists?(:table_name, :column_name)
      add_column :table_name, :column_name, :data_type
    end
  end