mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
Added protection against duplicate migration names (Aslak Hellesøy) [#112 state:resolved]
This commit is contained in:
committed by
David Heinemeier Hansson
parent
4cc594bd70
commit
10fdf44236
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Added protection against duplicate migration names (Aslak Hellesøy) [#112]
|
||||
|
||||
* Base#instantiate_time_object: eliminate check for Time.zone, since we can assume this is set if time_zone_aware_attributes is set to true [Geoff Buesing]
|
||||
|
||||
* Time zone aware attribute methods use Time.zone.parse instead of #to_time for String arguments, so that offset information in String is respected. Resolves #105. [Scott Fleckenstein, Geoff Buesing]
|
||||
|
||||
@@ -8,6 +8,12 @@ module ActiveRecord
|
||||
end
|
||||
end
|
||||
|
||||
class DuplicateMigrationNameError < ActiveRecordError#:nodoc:
|
||||
def initialize(name)
|
||||
super("Multiple migrations have the name #{name}")
|
||||
end
|
||||
end
|
||||
|
||||
class UnknownMigrationVersionError < ActiveRecordError #:nodoc:
|
||||
def initialize(version)
|
||||
super("No migration with version number #{version}")
|
||||
@@ -440,6 +446,10 @@ module ActiveRecord
|
||||
if klasses.detect { |m| m.version == version }
|
||||
raise DuplicateMigrationVersionError.new(version)
|
||||
end
|
||||
|
||||
if klasses.detect { |m| m.name == name.camelize }
|
||||
raise DuplicateMigrationNameError.new(name.camelize)
|
||||
end
|
||||
|
||||
load(file)
|
||||
|
||||
|
||||
@@ -984,6 +984,12 @@ if ActiveRecord::Base.connection.supports_migrations?
|
||||
end
|
||||
end
|
||||
|
||||
def test_migrator_with_duplicate_names
|
||||
assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
|
||||
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil)
|
||||
end
|
||||
end
|
||||
|
||||
def test_migrator_with_missing_version_numbers
|
||||
assert_raise(ActiveRecord::UnknownMigrationVersionError) do
|
||||
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Chunky < ActiveRecord::Migration
|
||||
def self.up
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class Chunky < ActiveRecord::Migration
|
||||
def self.up
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user