Skip to content

Commit

Permalink
Don't ignore :precision and :scale when adding columns on postgresql. C…
Browse files Browse the repository at this point in the history
…loses #6868 [w.piekutowski]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8647 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Jan 16, 2008
1 parent b812b23 commit 61e550a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -587,13 +587,14 @@ def rename_table(name, new_name)
execute "ALTER TABLE #{name} RENAME TO #{new_name}" execute "ALTER TABLE #{name} RENAME TO #{new_name}"
end end


# Adds a column to a table. # 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 = {}) def add_column(table_name, column_name, type, options = {})
default = options[:default] default = options[:default]
notnull = options[:null] == false notnull = options[:null] == false


# Add the column. # Add the column.
execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit])}") execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quoted_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_default(table_name, column_name, default) if options_include_default?(options)
change_column_null(table_name, column_name, false, default) if notnull change_column_null(table_name, column_name, false, default) if notnull
Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/migration_test.rb
Expand Up @@ -268,6 +268,15 @@ def test_native_decimal_insert_manual_vs_automatic
Person.reset_column_information Person.reset_column_information
end end


def test_add_column_with_precision_and_scale
Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7
Person.reset_column_information

wealth_column = Person.columns_hash['wealth']
assert_equal 9, wealth_column.precision
assert_equal 7, wealth_column.scale
end

def test_native_types def test_native_types
Person.delete_all Person.delete_all
Person.connection.add_column "people", "last_name", :string Person.connection.add_column "people", "last_name", :string
Expand Down

0 comments on commit 61e550a

Please sign in to comment.