From ca8561dec829d50a10ae05cefe951bc8f1a2a8c8 Mon Sep 17 00:00:00 2001 From: pjurewicz Date: Mon, 4 Sep 2023 18:56:10 +0200 Subject: [PATCH] Avoid multiple migrations having the same version number --- ...oreign_key_on_event_id_migration_generator_spec.rb | 2 +- ...ils_foreign_key_on_event_id_migration_generator.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rails_event_store/spec/rails_foreign_key_on_event_id_migration_generator_spec.rb b/rails_event_store/spec/rails_foreign_key_on_event_id_migration_generator_spec.rb index 25efdae237..49d152eaaa 100644 --- a/rails_event_store/spec/rails_foreign_key_on_event_id_migration_generator_spec.rb +++ b/rails_event_store/spec/rails_foreign_key_on_event_id_migration_generator_spec.rb @@ -78,7 +78,7 @@ def generate_migration end def second_step_migration_exists?(dir) - File.exist?("#{dir}/db/migrate/20160809222222_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb") + File.exist?("#{dir}/db/migrate/20160809222223_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb") end def generated_files_count(dir) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb index 3a2d12fd41..6b689d28e8 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/rails_foreign_key_on_event_id_migration_generator.rb @@ -27,13 +27,14 @@ def initialize(*args) def create_migration case @database_adapter when DatabaseAdapter::PostgreSQL + time = Time.now template "#{@database_adapter.template_directory}add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb", - "db/migrate/#{timestamp}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" + "db/migrate/#{migration_verion_number(time)}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" template "#{@database_adapter.template_directory}validate_add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb", - "db/migrate/#{timestamp}_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" + "db/migrate/#{migration_verion_number(time + 1)}_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" else template "#{@database_adapter.template_directory}add_foreign_key_on_event_id_to_event_store_events_in_streams_template.erb", - "db/migrate/#{timestamp}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" + "db/migrate/#{migration_verion_number(Time.now)}_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb" end end @@ -47,8 +48,8 @@ def migration_version ::ActiveRecord::Migration.current_version end - def timestamp - Time.now.strftime("%Y%m%d%H%M%S") + def migration_verion_number(time) + time.strftime("%Y%m%d%H%M%S") end end end