From e45a9e1a323bacee4b213c4064f7a1b942b17464 Mon Sep 17 00:00:00 2001 From: John Barker Date: Tue, 26 Apr 2011 00:00:02 +0800 Subject: [PATCH] When adding a column, does the alter table in one statement, rather than several separate statements. Makes sure the defaults get applied to existing columns properly. (Just taken from master branch) --- .../connection_adapters/postgresql_adapter.rb | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index a348318..7118583 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -806,14 +806,10 @@ module ActiveRecord # Adds a new column to the named table. # See TableDefinition#column for details of the options you can use. def add_column(table_name, column_name, type, options = {}) - default = options[:default] - notnull = options[:null] == false + add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}" + add_column_options!(add_column_sql, options) - # Add the column. - execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}") - - change_column_default(table_name, column_name, default) if options_include_default?(options) - change_column_null(table_name, column_name, false, default) if notnull + execute add_column_sql end # Changes the column of a table. -- 1.7.4.4