Skip to content
This repository
Browse code

DRY up PG's add_column a bit to use change_column_default and match t…

…he other

methods.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3324 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d5441b2d506b4286e92746abd8c919e4ce10380e 1 parent 1d2c6ee
Scott Barron authored December 20, 2005
12  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -296,15 +296,9 @@ def rename_table(name, new_name)
296 296
       end
297 297
             
298 298
       def add_column(table_name, column_name, type, options = {})
299  
-        native_type = native_database_types[type]
300  
-        sql_commands = ["ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"]
301  
-        if options.has_key?(:default)
302  
-          sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET DEFAULT '#{options[:default]}'"
303  
-        end
304  
-        if options[:null] == false
305  
-          sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL"
306  
-        end
307  
-        sql_commands.each { |cmd| execute(cmd) }
  299
+        execute("ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}")
  300
+        execute("ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL") if options[:null] == false
  301
+        change_column_default(table_name, column_name, options[:default]) unless options[:default].nil?
308 302
       end
309 303
 
310 304
       def change_column(table_name, column_name, type, options = {}) #:nodoc:

0 notes on commit d5441b2

Please sign in to comment.
Something went wrong with that request. Please try again.