mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added protection against duplicate migration names (Aslak Hellesøy) [#112 state:resolved]
This commit is contained in:
parent
4cc594bd70
commit
10fdf44236
5 changed files with 32 additions and 0 deletions
|
@ -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}")
|
||||
|
@ -441,6 +447,10 @@ module ActiveRecord
|
|||
raise DuplicateMigrationVersionError.new(version)
|
||||
end
|
||||
|
||||
if klasses.detect { |m| m.name == name.camelize }
|
||||
raise DuplicateMigrationNameError.new(name.camelize)
|
||||
end
|
||||
|
||||
load(file)
|
||||
|
||||
klasses << returning(name.camelize.constantize) do |klass|
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue