aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Barron <scott@elitists.net>2005-12-20 20:37:19 +0000
committerScott Barron <scott@elitists.net>2005-12-20 20:37:19 +0000
commitd5441b2d506b4286e92746abd8c919e4ce10380e (patch)
treee2dbd693a2a20bbc178cef61dc240a842de70819
parent1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace (diff)
downloadrails-d5441b2d506b4286e92746abd8c919e4ce10380e.tar.gz
rails-d5441b2d506b4286e92746abd8c919e4ce10380e.tar.bz2
rails-d5441b2d506b4286e92746abd8c919e4ce10380e.zip
DRY up PG's add_column a bit to use change_column_default and match the other
methods. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3324 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 76b72f3bd1..e3059ea010 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -296,15 +296,9 @@ module ActiveRecord
end
def add_column(table_name, column_name, type, options = {})
- native_type = native_database_types[type]
- sql_commands = ["ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"]
- if options.has_key?(:default)
- sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET DEFAULT '#{options[:default]}'"
- end
- if options[:null] == false
- sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL"
- end
- sql_commands.each { |cmd| execute(cmd) }
+ execute("ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}")
+ execute("ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL") if options[:null] == false
+ change_column_default(table_name, column_name, options[:default]) unless options[:default].nil?
end
def change_column(table_name, column_name, type, options = {}) #:nodoc: