Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make the migration generator handle pre-existing migrations with the …

…same timestamp.

In the event a migration already exists with that number, the new migration's timestamp will be incremented by 1.

[#4412 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
commit 64373937a393518a6e6a63255176ca297d3c009e 1 parent eb83c9c
@phs phs authored NZKoz committed
View
5 activerecord/lib/rails/generators/active_record.rb
@@ -19,10 +19,11 @@ def self.source_root
# Implement the required interface for Rails::Generators::Migration.
#
def self.next_migration_number(dirname) #:nodoc:
+ next_migration_number = current_migration_number(dirname) + 1
if ActiveRecord::Base.timestamped_migrations
- Time.now.utc.strftime("%Y%m%d%H%M%S")
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
else
- "%.3d" % (current_migration_number(dirname) + 1)
+ "%.3d" % next_migration_number
end
end
end
View
13 railties/test/generators/migration_generator_test.rb
@@ -10,6 +10,19 @@ def test_migration
assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/
end
+ def test_migrations_generated_simultaneously
+ migrations = ["change_title_body_from_posts", "change_email_from_comments"]
+
+ first_migration_number, second_migration_number = migrations.collect do |migration|
+ run_generator [migration]
+ file_name = migration_file_name "db/migrate/#{migration}.rb"
+
+ File.basename(file_name).split('_').first
+ end
+
+ assert_not_equal first_migration_number, second_migration_number
+ end
+
def test_migration_with_class_name
migration = "ChangeTitleBodyFromPosts"
run_generator [migration]

1 comment on commit 6437393

@parndt

This is an excellent move, thanks!

Please sign in to comment.
Something went wrong with that request. Please try again.