method
add_column
v1.2.6 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (10)
- 2.1.0 (30)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
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