From 4377f8eba2dde51fe5d3bc50248c0089e24c8d24 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 8 Oct 2010 21:17:14 +0200 Subject: Change the method for copying migrations, do not add scope. The purpose of this change is to allow copying fail on the same names. Migrations change database and they should be treated with caution, if 2 migrations are named the same it's much better to skip migration and allow user decide if it should be copied or not. --- activerecord/lib/active_record/migration.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record/migration.rb') diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 9ac18f9939..3fc69d7af0 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -387,18 +387,18 @@ module ActiveRecord def copy(destination, sources) copied = [] - sources.each do |scope, path| + sources.each do |name, path| destination_migrations = ActiveRecord::Migrator.migrations(destination) source_migrations = ActiveRecord::Migrator.migrations(path) last = destination_migrations.last source_migrations.each do |migration| - next if destination_migrations.any? { |m| m.name == migration.name && m.scope == scope.to_s } + next if destination_migrations.any? { |m| m.name == migration.name } migration.version = next_migration_number(last ? last.version + 1 : 0).to_i last = migration - new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{scope}.rb") + new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.rb") FileUtils.cp(migration.filename, new_path) copied << new_path end @@ -419,9 +419,9 @@ module ActiveRecord # MigrationProxy is used to defer loading of the actual migration classes # until they are needed - class MigrationProxy < Struct.new(:name, :version, :filename, :scope) + class MigrationProxy < Struct.new(:name, :version, :filename) - def initialize(name, version, filename, scope) + def initialize(name, version, filename) super @migration = nil end @@ -510,18 +510,18 @@ module ActiveRecord seen = Hash.new false migrations = files.map do |file| - version, name, scope = file.scan(/([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?.rb/).first + version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first raise IllegalMigrationNameError.new(file) unless version version = version.to_i name = name.camelize raise DuplicateMigrationVersionError.new(version) if seen[version] - raise DuplicateMigrationNameError.new(name) if seen[[name, scope]] + raise DuplicateMigrationNameError.new(name) if seen[name] - seen[version] = seen[[name, scope]] = true + seen[version] = seen[name] = true - MigrationProxy.new(name, version, file, scope) + MigrationProxy.new(name, version, file) end migrations.sort_by(&:version) -- cgit v1.2.3