-
Notifications
You must be signed in to change notification settings - Fork 11
Extend configuration to support disable_during_db_migrate
#34
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
base: master
Are you sure you want to change the base?
Conversation
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.
Important
Looks good to me! 👍
Reviewed everything up to 8a78a4e in 2 minutes and 10 seconds. Click for details.
- Reviewed
64lines of code in3files - Skipped
0files when reviewing. - Skipped posting
4draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. README.md:72
- Draft comment:
Consider expanding the explanation in this new 'Disable duringdb:migrate' section. A brief note on why and when you might want to disable formatting could help users. - Reason this comment was not posted:
Confidence changes required:20%<= threshold50%None
2. lib/pp_sql.rb:9
- Draft comment:
Add a brief comment for the new 'disable_during_db_migrate' flag to explain its purpose, similar to the other flags. - Reason this comment was not posted:
Confidence changes required:30%<= threshold50%None
3. lib/pp_sql/tasks/db_hooks.rake:6
- Draft comment:
Consider logging a message when pp_sql formatting is disabled during db:migrate to aid in debugging. - Reason this comment was not posted:
Confidence changes required:30%<= threshold50%None
4. lib/pp_sql/tasks/db_hooks.rake:4
- Draft comment:
Typo: In the description string, "Hook that is ran before rails db:migrate...", 'ran' should be changed to 'run'. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While the grammar correction is technically correct, this is just a task description string that developers will rarely see. It doesn't affect functionality. The meaning is still perfectly clear despite the minor grammatical error. The rules say to only keep comments that require clear code changes, and to avoid unimportant changes. The grammar mistake could be seen as unprofessional, and fixing it would improve code quality. Documentation is also code. While documentation quality matters, this is an extremely minor issue that doesn't impact understanding or functionality. The rules specifically say to avoid obvious or unimportant comments. This comment should be deleted as it suggests a trivial change that doesn't meaningfully impact code quality or functionality.
Workflow ID: wflow_CoMhZmbANoa2SAyV
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
|
Thank you for your contribution! Regarding the case you are covering, i suppose that the migrations are not the only Rails rake tasks that might be affected by this problem, and other DB operations are at risk. May I ask you to extend that to dynamically loaded Rails With the enhancement mentioned before, it might require improving the naming of the function to be more generic, since it'll be not only about the migrations. and add an env var trigger to that, something like The readme section will also require the changes, which should be done under Rails section, since it's the code that will be used by Rails users only. wdyt about this? |
|
Thanks for the quick response!
Ah, so you are suggesting that |
|
@kvokka I've made some changes but not yet tested. Let me know what you think. I had the thought that maybe your suggestion regarding |
|
@kvokka I've tested the latest version with some different combinations. I used the following script in my local project: Here are the results: There is still an outstanding TODO here to document usage of the env var in the readme (as well as correct some of the other newly added info?). However, I wanted to make sure these changes are inline with what you were requesting before making the final readme change. |
kvokka
left a comment
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.
Please keep in mind the changes that I left in the review comments, which will provide the same functionality, but by extending the code only.
lib/pp_sql.rb
Outdated
| attr_accessor :rewrite_to_sql_method, :add_rails_logger_formatting | ||
| attr_accessor :rewrite_to_sql_method, :add_rails_logger_formatting, :disable_for_db_tasks | ||
|
|
||
| def enabled_for?(action) |
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.
it's a bit odd, since with this lately u'r wrapping the boolean settings with another one. Seems to be excessive
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.
Since I was originally using a disabled_ accessor the logic was feeling hard to read (if enabled && !ENV[disabled]) so pulling it into a single method felt cleaner. However, based on your other suggestions the disabled ENV can go away so I'll remove this method.
| ActiveRecord::LogSubscriber.prepend LogSubscriberPrettyPrint | ||
| end | ||
| end | ||
|
|
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.
rake_tasks do
path = File.expand_path(__dir__)
load("#{path}/pp_sql/tasks/db_hooks.rake") unless PpSql.enable_for_rails_rake_db_tasks
end| namespace :pp_sql do | ||
| desc 'Hook that is ran before rails `db:*` tasks that can disable pp_sql' | ||
|
|
||
| task :disable_during_db_tasks do |
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.
task :disable_during_db_tasks do
PpSql.add_rails_logger_formatting = false
PpSql.rewrite_to_sql_method = false
end
end
lib/pp_sql.rb
Outdated
| end | ||
| self.rewrite_to_sql_method = true | ||
| self.add_rails_logger_formatting = true | ||
| self.disable_for_db_tasks = true |
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.
self.enable_for_rails_rake_db_tasks = ENV['PPSQL_ENABLE_FOR_RAILS_RAKE_DB_TASKS']
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.
From testing, something I didn't quite realize is that this file and the rake tasks are loaded before any of the local project files/initializers are read. This means that setting enable_for_rails_rake_db_tasks within the project won't have any effect because the rake task loading will have already been executed (or skipped). In other words, with the current changes, the only way to opt into formatting is by usage of the ENV var. Is that ok?
|
@kvokka Latest testing round, slightly updated script: Results: |
|
@kvokka I wanted to check in and see if there are other changes you would like on this branch that could unblock it. Thanks! |
As mentioned in #33, parsing of the sql messages can have a large impact on the schema dump process when running
rails db:migrate. The intent of this change is to allow for a configurable option to allow users/teams to opt out of the formatting during the migration process. This allows for consumers ofpp_sqlto leverage it for formatting within their environment without having to suffer the performance cost when migrating their database.To opt-in, simply add
PpSql.disable_during_db_migrate = truewithin the specific envrionment file or within the initializer. By opting intodisable_during_db_migrate, a before hook will be ran in front ofdb:migratetask that will set bothrewrite_to_sql_methodandadd_rails_logger_formattingtofalsefor the duration of the task.Important
Add
disable_during_db_migrateoption toPpSqlto disable SQL formatting duringrails db:migrate, with documentation updates.disable_during_db_migrateoption toPpSqlinlib/pp_sql.rbto disable SQL formatting duringrails db:migrate.pp_sql:disable_during_db_migrateindb_hooks.raketo setadd_rails_logger_formattingandrewrite_to_sql_methodto false ifdisable_during_db_migrateis true.README.mdto include instructions for usingdisable_during_db_migrateoption.This description was created by
for 8a78a4e. You can customize this summary. It will automatically update as commits are pushed.