-
-
Notifications
You must be signed in to change notification settings - Fork 61
Fix environment mismatch error in docker env tests #722
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
Fix environment mismatch error in docker env tests #722
Conversation
Fixes `ActiveRecord::EnvironmentMismatchError` after a `bin/dev/bootstrap` and `bin/dev/test`. TLDR; The `development` and `test` environments were sharing the `mutualaid` database instead of being isolated in their own databases. References ---------- - #718
grenewode
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.
This looks pretty good to me - although I'm really only a casual dev-opser, and I can already tell your bash-foo is stronger than mine 😉 I do think it would be good to keep the ability to set the database with an environment variable when the docker image is built though.
solebared
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.
Awesome! Thanks for looking into this 🙏🏾.
TBH, i'm still not sure the exact sequence of how all the pieces fit together, but i trust you and @grenewode on this 🧙🏾♂️.
| username: <%= ENV.fetch('POSTGRES_USER', nil) %> | ||
| password: <%= ENV.fetch('POSTGRES_PASSWORD', nil) %> | ||
| database: <%= ENV.fetch('POSTGRES_DB', nil) %> | ||
| username: <%= ENV['POSTGRES_USER'].presence || nil %> | ||
| password: <%= ENV['POSTGRES_PASSWORD'].presence || nil %> | ||
| database: <%= ENV['POSTGRES_DB'].presence || nil %> |
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.
To make sure i'm tracking: we're switching to presence because we want to ignore blank strings, whereas fetch would only ignore nils, correct?
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.
💯That is correct.
The idea is that presence will return the contents of the ENV var when the ENV var contains what Ruby considers a truth-y value:
# WUMPUS=1
ENV['WUMPUS'].presence
# => "1"
# WUMPUS=found_me
ENV['WUMPUS'].presence
# => "found_me"
# WUMPUS=true
ENV['WUMPUS'].presence
# => "true"
# WUMPUS=false
ENV['WUMPUS'].presence
# => "false"but will return nil when the ENV var is unset, or contains a false-y value:
# WUMPUS=
ENV['WUMPUS'].presence
# => nil
# WUMPUS=''
ENV['WUMPUS'].presence
# => nilThe presence method is functionally equivalent to object.present? ? object : nil.
|
Thanks all, for the great conversations, and guidance. |
Fixes
ActiveRecord::EnvironmentMismatchErrorafter abin/dev/bootstrapandbin/dev/test.TLDR; The
developmentandtestenvironments were sharing themutualaiddatabase instead of being isolated in their own databases.References