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

Migrations generator assumes migrations are in db/migrate #352

Closed
zachmargolis opened this issue Aug 26, 2021 · 4 comments · Fixed by #354
Closed

Migrations generator assumes migrations are in db/migrate #352

zachmargolis opened this issue Aug 26, 2021 · 4 comments · Fixed by #354

Comments

@zachmargolis
Copy link
Contributor

tl;dr

Would like bin/rails g good_job:update to allow us to specify a separate DB or separate migrations directory, like the --database option in rails generate migration

Background

In our app, we have set up the good_jobs table in a separate database from our main application.

Per the ActiveRecord multiple databases guide, we use the migrations_paths config to put those migrations are in db/worker_jobs_migrate instead of the normal db/migrate.

When generating migrations, we use the --database CLI arg to specify worker_jobs so Rails knows to put things in the right spot, ex:

bin/rails generate migration CreateDogs name:string --database worker_jobs

However, GoodJob assumes migrations are in db/migrate:

migration_template "migrations/#{template_file}", "db/migrate/#{destination_file}", skip: true

Problems

Since our migrations are in a different place, GoodJob is unable to detect migrations that have already happened to give us diffs

@zachmargolis
Copy link
Contributor Author

Also, slightly related:

class GoodJobJobs < ActiveRecord::Base
self.table_name = "good_jobs"
end

I can't tell exactly where this comes from, but inside the migrations they create a model that inherits from ActiveRecord::Base to do a migration but we'd need ours to come from GoodJob.active_record_parent_class instead for similar reasons

zachmargolis added a commit to 18F/identity-idp that referenced this issue Aug 26, 2021
- Temporarily added a symlink from db/migrate => db/worker_jobs_migrate
  to work around bensheldon/good_job#352
zachmargolis added a commit to 18F/identity-idp that referenced this issue Aug 26, 2021
* Rename migration back to default good_job name, used for migration detection

* bin/rails g good_job:update

- Temporarily added a symlink from db/migrate => db/worker_jobs_migrate
  to work around bensheldon/good_job#352

* Patch GoodJob migration to use correct base class
@bensheldon
Copy link
Owner

Oh! Both of these are unfortunate.

I will see if there is a simple way to pass down the options flag. I have regrets not using the default Rails::Engine mechanism for generating database migrations (I only recently learned about that).

And thank you for flagging the ideal base class in the migration; that's a quick fix.

@bensheldon
Copy link
Owner

Released in v1.99.1 and v2.0.2. Thank you!

@zachmargolis
Copy link
Contributor Author

Such a fast turnaround! Thank you! 🙌 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants