Migrations: raise if a column is duplicated. Closes #7345.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6961 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper
2007-06-07 23:25:50 +00:00
parent c7df5bd6ac
commit 869a172a8a
3 changed files with 20 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
*SVN*
* Migrations: raise if a column is duplicated. #7345 [Jeremy McAnally, Josh Peek]
* Fixtures: correctly delete and insert fixtures in a single transaction. #8553 [Michael Schuerig]
* Fixtures: people(:technomancy, :josh) returns both fixtures. #7880 [technomancy, Josh Peek]

View File

@@ -351,7 +351,8 @@ module ActiveRecord
# There's a short-hand method for each of the type values declared at the top. And then there's
# TableDefinition#timestamps that'll add created_at and updated_at as datetimes.
def column(name, type, options = {})
column = self[name] || ColumnDefinition.new(@base, name, type)
raise "You already defined column '#{name}'." if self[name]
column = ColumnDefinition.new(@base, name, type)
column.limit = options[:limit] || native[type.to_sym][:limit] if options[:limit] or native[type.to_sym]
column.precision = options[:precision]
column.scale = options[:scale]

View File

@@ -807,6 +807,22 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
def test_should_disallow_duplicate_column_definition
assert_raises(ActiveRecord::StatementInvalid) do
Person.connection.add_column("people", "full_name", :string, :limit => 40)
Person.connection.add_column("people", "full_name", :text)
end
assert_raises(RuntimeError) do
Person.connection.create_table :people_with_errors do |t|
t.column "full_name", :string, :limit => 40
t.column "full_name", :text
end
end
Person.reset_column_information
end
end
end