Skip to content

Commit

Permalink
Added protection against duplicate migration names (Aslak Hellesøy) [#…
Browse files Browse the repository at this point in the history
…112 state:resolved]
  • Loading branch information
aslakhellesoy authored and dhh committed May 11, 2008
1 parent 4cc594b commit 10fdf44
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -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]
Expand Down
10 changes: 10 additions & 0 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -8,6 +8,12 @@ def initialize(version)
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}")
Expand Down Expand Up @@ -440,6 +446,10 @@ def migrations
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)

Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -984,6 +984,12 @@ def test_migrator_with_duplicates
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)
Expand Down
@@ -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

0 comments on commit 10fdf44

Please sign in to comment.