method
add_column
add_column(table_name, column_name, type, options = {})
public
Hide source
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 321 def add_column(table_name, column_name, type, options = {}) default = options[:default] notnull = options[:null] == false # Add the column. execute("ALTER TABLE #{table_name} ADD COLUMN #{column_name} #{type_to_sql(type, options[:limit])}") # Set optional default. If not null, update nulls to the new default. if options_include_default?(options) change_column_default(table_name, column_name, default) if notnull execute("UPDATE #{table_name} SET #{column_name}=#{quote(default, options[:column])} WHERE #{column_name} IS NULL") end end if notnull execute("ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL") end end


