Skip to content

Commit

Permalink
Avoid multiple migrations having the same version number
Browse files Browse the repository at this point in the history
  • Loading branch information
pjurewicz committed Sep 4, 2023
1 parent 459f443 commit ca8561d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit ca8561d

Please sign in to comment.