Browse files

Give a nice message if there are duplicate migrations instead of rais…

…ing a strange insert error
  • Loading branch information...
1 parent faec7f5 commit b69de8c5fd793730b57ae856ee54cf59c9605336 @jeremy jeremy committed Jun 4, 2008
Showing with 14 additions and 3 deletions.
  1. +14 −3 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
View
17 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -331,15 +331,26 @@ def initialize_schema_migrations_table
end
def assume_migrated_upto_version(version)
+ version = version.to_i
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
+
migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
filename.split('/').last.split('_').first.to_i
end
- execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" unless migrated.include?(version.to_i)
- (versions - migrated).select { |v| v < version.to_i }.each do |v|
- execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')"
+ unless migrated.include?(version)
+ execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')"
+ end
+
+ inserted = Set.new
+ (versions - migrated).each do |v|
+ if inserted.include?(v)
+ raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict."
+ elsif v < version
+ execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')"
+ inserted << v
+ end
end
end

0 comments on commit b69de8c

Please sign in to comment.