-
Notifications
You must be signed in to change notification settings - Fork 114
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
Only run pending migrations check if necessary #1418
Conversation
8a27b34
to
299f851
Compare
|
||
sig { void } | ||
def abort_if_pending_migrations! | ||
return unless File.exist?("#{@app_root}/config/application.rb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally dropped this line when moving this helper method since it would require us to thread app_root
further down into Dsl::Pipeline
. It was added in the original PR that added this check (89de7fd#diff-3c285599de82036518463c68957ff3a1b87239257be68b33041c5b9bef3dba1aR700) but I can't really tell what it's trying to do. My best guess is that it's trying to ensure we're inside a Rails app and since this check is now conditionalized on ActiveRecord::Base
being defined I think we can rely on that for the same assumption check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the idea was to check if we were in a Rails app before it was loaded. I agree that we probably won't need it if we can check for ActiveRecord::Base
.
299f851
to
66e1198
Compare
|
||
sig { void } | ||
def abort_if_pending_migrations! | ||
return unless File.exist?("#{@app_root}/config/application.rb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the idea was to check if we were in a Rails app before it was loaded. I agree that we probably won't need it if we can check for ActiveRecord::Base
.
You have 1 pending migration: | ||
202001010000_create_articles.rb | ||
OUT | ||
# FIXME: print the error to the correct stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
66e1198
to
844751a
Compare
|
||
sig { void } | ||
def abort_if_pending_migrations! | ||
return unless defined?(::Rake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may not even need this one now that we're further down the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this line as well 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to put this back since it broke some tests (e.g. https://github.com/Shopify/tapioca/actions/runs/4317148630/jobs/7533849593#step:6:410). Couldn't hurt to be a little cautious here.
63b3a63
to
921f11b
Compare
cc @paracycle @vinistock - I think there's something wrong with the test suite. Some unrelated specs for |
@jeffcarbs thanks for reporting! I believe we found the problem; I'll ping this PR to let you know to rebase once we've fixed it. |
@jeffcarbs sorry about the delay; the CI issue has been fixed. Can you push your changes again? |
942f2a6
to
a53969c
Compare
Thanks @dirceu, looks like it's working now! @vinistock - I've put the changes back and the build is green so this should be good to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a small comment about safety in the presence of arbitrary constants, otherwise, this is great work. Thanks for the PR!
1205840
to
9139ce6
Compare
Motivation
A point of friction we've experienced is getting blocked from running DSL generation due to pending migration even when we're not generating RBI for ActiveRecord models (e.g. when doing something like
bin/tapioca dsl Some::Sidekiq::Worker Some::Graphql::Mutation
) . The pending migration check is valuable to ensure we don't generate ActiveRecord RBI with a stale schema, but it's irrelevant when generating RBI for things like sidekiq workers, graphql mutations, or other non-ActiveRecord things.Implementation
Since we want to conditionalize running the pending migrations check, we need to be at a point where we have the constants we're going to process in memory. This means we need to pull the pending migrations check out from the
Loaders::Dsl
further down into theDsl::Pipeline
. We then check to see if any of the constants we're going to process subclass ActiveRecord::Base and only check for pending migrations then.This handles both the case where you don't give specific classes (
bin/tapioca dsl
) or you give some (bin/tapioca dsl Something
) and there are test cases for both scenarios.A small side-benefit here is that previously even a command like
bin/tapiocs dsl --list-compilers
would fail due to pending migrations since that check happened when loading rails. Since it now only runs if necessary, that command would succeed.Tests
I refactored the existing pending migration test to reuse some pieces (see first commit) and then added some specific test cases for this.