-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Read Database Config From Env Variable For Rails/BulkChangeTable
#903
Read Database Config From Env Variable For Rails/BulkChangeTable
#903
Conversation
Rails/BulkChangeTable
Rails/BulkChangeTable
Rails/BulkChangeTable
Rails/BulkChangeTable
Rails/BulkChangeTable
case url | ||
when %r{\Amysql2://} | ||
MYSQL | ||
when %r{\Apostgres(ql)?://} |
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.
Rails normalizes postgres
to postgresql
in https://github.com/rails/rails/blob/f517eefe1450b900cf3e44b8e6830d917f1530c0/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb#L29
Something I found while trying to debug the difference in RuboCop offenses between our CI and the local development environment: https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/1029#note_499041793 |
@joergschiller Looks good to me. Can you squash your commits into one? |
@@ -207,6 +207,18 @@ def database_yaml | |||
nil | |||
end | |||
|
|||
def database_from_env | |||
url = ENV['DATABASE_URL'].presence |
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 would be good to document this ENV['DATABASE_URL']
behavior.
6845469
to
bda5de3
Compare
@koic thanks for considering the changes. I've added a short description about the behaviour to the cop documentation. I also rebased on master and squashed the commits. |
Thanks! |
Rails/BulkChangeTable
currently reads information about the adapter from the development environment inconfig/database.yml
. It's not unusual to use the environment variableDATABASE_URL
instead of having a configuration file on CI (see 1 or 2).In this case the cop can't figure out if the adapter is supported and hence not warn about the potential use of
change_table
. Something that happens to me today.This PR tries to get the adapter from
DATABASE_URL
after trying to read fromconfig/database.yml
.Before submitting the PR make sure the following are checked:
Commit message starts with[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.If this is a new cop, consider making a corresponding update to the Rails Style Guide.