You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Install migration into project instead of running from gem #26
First of all, thanks for this library. I'm a newbie to Rails.
Running rake db:migrate runs migration from this gem, but I would like to have the migration in my project (which seems like a good practice in general)
Right now its hidden inside this gem and I will definitely forget about it or any new member to this project.
So I've ran rake active_currency:install:migrations which placed the files into my project like so
# 20230211200817_create_active_currency_rates.active_currency.rb# frozen_string_literal: true# This migration comes from active_currency (originally 20180911202100)require'active_currency/migration'classCreateActiveCurrencyRates < ActiveCurrency::Migrationdefchangecreate_table:active_currency_ratesdo |t|
t.string:fromt.string:tot.float:valuet.datetime:created_atendreversibledo |dir|
dir.updoadd_index:active_currency_rates,%i[fromtocreated_at],name: 'index_active_currency_rates'enddir.downdoremove_index:active_currency_rates,'index_active_currency_rates'endendendend
But now when I run rake db:migrate, it still tries to run this gem migration, causing
root@a864e105f4e5:/usr/src/app# ./bin/rake db:migrate
rake aborted!
ActiveRecord::DuplicateMigrationNameError:
Multiple migrations have the name CreateActiveCurrencyRates.
/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/migration.rb:1384:in `validate'/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/migration.rb:1257:in `initialize'/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/migration.rb:1117:in `new'/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/migration.rb:1117:in `up'
/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/migration.rb:1092:in `migrate'/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/tasks/database_tasks.rb:262:in `migrate'/usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/railties/databases.rake:92:in `block (2 levels) in<main>'Tasks: TOP => db:migrate(See full trace by running task with --trace)
I’ve used the gem and several others that work of the box without requiring to call the *:install:migrations task. Indeed schema.rb is the source of truth. However, I agree that there are less gems these days that follow this pattern, as it tends to hide the migrations a bit.
So perhaps it’s time to change this gem to ask users for this small extra step on install.
To do that we would need to:
update documentation to ask to call bin/rails active_currency:install:migrations
stop appending the gem’s migrations inside the Rails Engine
Would you be willing to start a pull-request with these changes? 🙏🏻
Activity
olso commentedon Feb 11, 2023
Maybe it doesn't matter, if
schema.rbis source of truth?sunny commentedon Feb 13, 2023
Hi @olso!
I’ve used the gem and several others that work of the box without requiring to call the
*:install:migrationstask. Indeedschema.rbis the source of truth. However, I agree that there are less gems these days that follow this pattern, as it tends to hide the migrations a bit.So perhaps it’s time to change this gem to ask users for this small extra step on install.
To do that we would need to:
bin/rails active_currency:install:migrationsWould you be willing to start a pull-request with these changes? 🙏🏻