Skip to content

Conversation

@indiebrain
Copy link
Collaborator

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

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
@indiebrain indiebrain self-assigned this Sep 23, 2020
Copy link
Contributor

@grenewode grenewode left a 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.

Copy link
Collaborator

@solebared solebared left a 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 🧙🏾‍♂️.

Comment on lines -30 to +32
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 %>
Copy link
Collaborator

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?

Copy link
Collaborator Author

@indiebrain indiebrain Sep 23, 2020

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  
# => nil

The presence method is functionally equivalent to object.present? ? object : nil.

@indiebrain indiebrain merged commit 869bfcb into main Sep 23, 2020
@indiebrain indiebrain deleted the fix-environment-mismatch-error-in-docker-env-tests branch September 23, 2020 14:38
@indiebrain
Copy link
Collaborator Author

Thanks all, for the great conversations, and guidance.

@indiebrain indiebrain linked an issue Sep 24, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remaining issues with docker development

5 participants