Method: ActiveRecord::ConnectionAdapters::SchemaStatements#build_add_column_definition

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

#build_add_column_definition(table_name, column_name, type, **options) ⇒ Object

Builds an AlterTable object for adding a column to a table.

This definition object contains information about the column that would be created if the same arguments were passed to #add_column. See #add_column for information about passing a table_name, column_name, type and other options that can be passed.



654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb', line 654

def build_add_column_definition(table_name, column_name, type, **options) # :nodoc:
  return if options[:if_not_exists] == true && column_exists?(table_name, column_name)

  if supports_datetime_with_precision?
    if type == :datetime && !options.key?(:precision)
      options[:precision] = 6
    end
  end

  alter_table = create_alter_table(table_name)
  alter_table.add_column(column_name, type, **options)
  alter_table
end