RailsEventStore / rails_event_store

A Ruby implementation of an Event Store based on Active Record
http://railseventstore.org
MIT License
1.4k stars 122 forks source link

The provided template for existing rails application doesn't work for rails_event_store 2.14.0 and rails 7.1.2 #1743

Closed socjopata closed 4 months ago

socjopata commented 5 months ago

Hi,

I am just letting you know that the https://railseventstore.org/docs/v2/install/#existing-rails-application doesn't seem to work for existing Rails applications. I tested it locally both on one of my pet projects running on Rails 7.1.2 and on a fresh, vanilla Rails project generated with 7.1.3, so hopefully you'll be able to recreate it easily too.

The problem is that the app:template script creates duplicate migrations, as can be seen on the screenshot here:

image

and fails on trying to migrate them both:

bin/rails app:template LOCATION=https://railseventstore.org/new
       apply  https://railseventstore.org/new
     gemfile    rails_event_store (~> 2.14.0)
 initializer    rails_event_store.rb
       route    mount RailsEventStore::Browser => '/res' if Rails.env.development?
         run    bundle check from "."
Could not find gem 'rails_event_store (~> 2.14.0)' in locally installed gems.
Run `bundle install --gemfile /home/beu/FreelanceProjects/lol/Gemfile` to install missing gems.
         run    bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Fetching arkency-command_bus 0.4.1
Fetching ruby_event_store 2.14.0
Installing arkency-command_bus 0.4.1
Installing ruby_event_store 2.14.0
Fetching ruby_event_store-browser 2.14.0
Fetching ruby_event_store-active_record 2.14.0
Fetching aggregate_root 2.14.0
Installing aggregate_root 2.14.0
Installing ruby_event_store-active_record 2.14.0
Installing ruby_event_store-browser 2.14.0
Fetching rails_event_store_active_record 2.14.0
Installing rails_event_store_active_record 2.14.0
Fetching rails_event_store 2.14.0
Installing rails_event_store 2.14.0
Bundle complete! 16 Gemfile dependencies, 91 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
       rails    db:create
Created database 'storage/development.sqlite3'
Created database 'storage/test.sqlite3'
    generate    rails_event_store_active_record:migration --data-type=binary
       rails    generate rails_event_store_active_record:migration --data-type=binary 
      create  db/migrate/20240215173726_create_event_store_events.rb
       rails    db:migrate
== 20240215173726 CreateEventStoreEvents: migrating ===========================
-- create_table(:event_store_events_in_streams, {:force=>false})
   -> 0.0013s
-- add_index(:event_store_events_in_streams, [:stream, :position], {:unique=>true})
   -> 0.0004s
-- add_index(:event_store_events_in_streams, [:stream, :event_id], {:unique=>true})
   -> 0.0004s
-- add_index(:event_store_events_in_streams, [:event_id])
   -> 0.0004s
-- create_table(:event_store_events, {:force=>false})
   -> 0.0019s
-- add_foreign_key("event_store_events_in_streams", "event_store_events", {:column=>"event_id", :primary_key=>"event_id"})
   -> 0.0106s
== 20240215173726 CreateEventStoreEvents: migrated (0.0150s) ==================

         run  bundle install
Bundle complete! 16 Gemfile dependencies, 91 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
       rails  db:create
Database 'storage/development.sqlite3' already exists
Database 'storage/test.sqlite3' already exists
    generate  rails_event_store_active_record:migration --data-type=binary
       rails  generate rails_event_store_active_record:migration --data-type=binary 
      create  db/migrate/20240215173728_create_event_store_events.rb
       rails  db:migrate
bin/rails aborted!
ActiveRecord::DuplicateMigrationNameError: 

Multiple migrations have the name CreateEventStoreEvents.

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Since Rails app:template command seems to execute the run_bundle and run_after_bundle_callbacks anyway, I quickfixed it for myself, by executing the provided template locally, with the following code part removed:

profile.for_existing_app do
  run_after_bundle_callbacks
end
mostlyobvious commented 4 months ago

Rails app:template command seems to execute the run_bundle and run_after_bundle_callbacks anyway

This must have changed in Rails 7.1: https://github.com/RailsEventStore/rails_event_store/commit/3a19ac8ca0e5b0928984086feb261a772a3e82ba

porbas commented 4 months ago

It's been changed with the commit: https://github.com/rails/rails/commit/83e69c22e9ebfb3585c0fb6d536353f4f43fd483 I'll add a version check to the template and conditionally run `run_after_bundle_check' only for versions older than 7.1.