From d5859d0b17ccbf5907a2eb2a979257ec6474e677 Mon Sep 17 00:00:00 2001 From: Florian Weber Date: Mon, 31 Oct 2005 15:43:02 +0000 Subject: Added that an DuplicateMigrationVersionError gets raised when multiple migrations have the same version number. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2832 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/migration.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 90984b080b..bf4f9aa530 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -2,6 +2,12 @@ module ActiveRecord class IrreversibleMigration < ActiveRecordError#:nodoc: end + class DuplicateMigrationVersionError < ActiveRecordError#:nodoc: + def initialize(version) + super("Multiple migrations have the version number #{version}") + end + end + # Migrations can manage the evolution of a schema used by several physical databases. It's a solution # to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to # push that change to other developers and to the production server. With migrations, you can describe the transformations @@ -209,15 +215,22 @@ module ActiveRecord private def migration_classes - migrations = migration_files.collect do |migration_file| + migrations = migration_files.inject([]) do |migrations, migration_file| load(migration_file) version, name = migration_version_and_name(migration_file) - [ version.to_i, migration_class(name) ] + assert_unique_migration_version(migrations, version.to_i) + migrations << [ version.to_i, migration_class(name) ] end - + down? ? migrations.sort.reverse : migrations.sort end - + + def assert_unique_migration_version(migrations, version) + if !migrations.empty? && migrations.transpose.first.include?(version) + raise DuplicateMigrationVersionError.new(version) + end + end + def migration_files files = Dir["#{@migrations_path}/[0-9]*_*.rb"].sort_by do |f| migration_version_and_name(f).first.to_i -- cgit v1.2.3