Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Feb 15, 2024 · 2 comments

Comments

@socjopata
Copy link

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
Copy link
Member

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

This must have changed in Rails 7.1:
3a19ac8

@porbas
Copy link
Contributor

porbas commented Mar 20, 2024

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

@porbas porbas closed this as completed in 046a59c Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants