-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat(database config): use DATABASE_URL in .env for all environments #610
base: main
Are you sure you want to change the base?
feat(database config): use DATABASE_URL in .env for all environments #610
Conversation
Hey! Thanks for the PR. I'm trying to understand what you mean by "not have tests trash my development database"? When you run your specs, you're saying that your dev db is truncated? I haven't seen that with any of my apps. Do you have your specs configured differently? this line sets your env to test which should make this line reference only a test db. I'm wondering if there's some other error, or maybe documentation we might have missed somewhere 🤔 |
If I use |
Oh, I see what you're saying. I looked at what my projects are doing for this since we only use .env files, and I noticed that I added this to all of them # spec/spec_helper.cr
require "dotenv"
Dotenv.load(".env.test") I definitely agree that this is an issue, but the one thing I'm not too sure of is this basically ignores whatever database name you set in your .env. For me, most of my Lucky apps were ported from older projects where the DB names are different, so they don't always follow the "appname_env" convention. What are your thoughts on using a |
Firstly, I should mention that I never thought that the proposed PR would be the final solution even if correct insofar as functionality is concerned, but rather is merely my less ideal solution which I'm using presently to make it work the way that I'd like. I presumed to think that the idea might fly, but that the implementation would be rejected because it's pretty ugly... One of the key aspects of the design ethos of Elixir at least insofar as how it is used is concerned, which which I get the sense is present also in Lucky and which is what attracted me to Lucky rather than using a Rails-clone in Crystal, is to do with obviousness or lack of magic perhaps. Elixir has an anti-DRY (or DRO as I like to call it) disposition because of what I presume to think is our shared experience of trawling through Rails or Rspec, but particularly Rails, seeing layers and layers of abstraction which in reality often makes things harder, not easier. So, your proposed solution works to the extent that I think it contains a little less magic and is therefore more obvious. In fact, I'm pretty sure that I had a similar set up in a Rails project not so long ago... I was wondering if it would it be even less magic and more obvious to have one .env file per environment, possibly with sensible fall backs? I think it would be clearer still if |
I'm not sold on what accrues from the additional commit, but rather am just playing with possible solutions, and it may not even work. Will need to spend more time on it later... |
Exactly. I do love Rails, but sometimes there's just a bit too much magic. With Lucky, we want things to be a bit more obvious and straight forward, even if it means just a little more typing, or a few more files. A little magic here and there is ok, but there has to be a nice balance. I don't think there's any major rush on this, so we can take some time to come up with a clean solution. If you happen to see what other frameworks are doing in this case (outside of rails or phoenix), feel free to drop some other ideas in here. Thanks for your help on this! |
This change allows the use of a single line in
.env
as per below:DATABASE_URL=postgres://lucky:developer@localhost:5432/<app_name>
and not have tests trash my development database, whilst still working as is for production.