Skip to content

Commit 89b1ceb

Browse files
committed
Avoid multiple non-rails migrations having the same version number
1 parent 3a9499b commit 89b1ceb

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/foreign_key_on_event_id_migration_generator.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ module RubyEventStore
44
module ActiveRecord
55
class ForeignKeyOnEventIdMigrationGenerator
66
def call(database_adapter, migration_path)
7-
each_migration(database_adapter) do |migration_name|
8-
path = build_path(migration_path, migration_name)
7+
time = Time.now
8+
each_migration(database_adapter) do |migration_name, i|
9+
path = build_path(migration_path, migration_name, time + i)
910
write_to_file(path, migration_code(database_adapter, migration_name))
1011
end
1112
end
@@ -21,7 +22,7 @@ def each_migration(database_adapter, &block)
2122
]
2223
else
2324
['add_foreign_key_on_event_id_to_event_store_events_in_streams']
24-
end.each(&block)
25+
end.each.with_index(&block)
2526
end
2627

2728
def absolute_path(path)
@@ -52,8 +53,12 @@ def write_to_file(path, migration_code)
5253
File.write(path, migration_code)
5354
end
5455

55-
def build_path(migration_path, migration_name)
56-
File.join("#{migration_path}", "#{timestamp}_#{migration_name}.rb")
56+
def build_path(migration_path, migration_name, time)
57+
File.join("#{migration_path}", "#{migration_verion_number(time)}_#{migration_name}.rb")
58+
end
59+
60+
def migration_verion_number(time)
61+
time.strftime("%Y%m%d%H%M%S")
5762
end
5863
end
5964
end

ruby_event_store-active_record/spec/foreign_key_on_event_id_migration_generator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def read_migration(dir)
8383
end
8484

8585
def second_step_migration_exists?(dir)
86-
File.exist?("#{dir}/20221130213700_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb")
86+
File.exist?("#{dir}/20221130213701_validate_add_foreign_key_on_event_id_to_event_store_events_in_streams.rb")
8787
end
8888

8989
def generated_files_count(dir)

0 commit comments

Comments
 (0)