-
Notifications
You must be signed in to change notification settings - Fork 81
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
DATABASE_URL should take precedence over database.yml #138
Comments
Hi @jnicklas, thanks for raising the issue. We're indeed using what's in the database.yml file first, and only if there's no url in there we're setting it from Then later when calling There's multiple issue there:
Not sure what's the best way to tackle them. For 1, If I recall correctly (it's been more than 3 years I checked), there's a good chunk of code in Rails/AR, specific to each supported database to handle the conversion from URL to connection params, I'm really not fond of trying to do such thing. I would prefer to let Sequel handle most of that itself. For 2, this allows to easily pass specific database connection options to I'm open to propositions to better handle those cases. |
To be fair, we're in fact already constructing url to handle I'm wondering how much people are relying on the combo of DATABASE_URL from env + merge other option from config... |
I think the best practice is to put |
+1 for this feature. I also expected DATABASE_URL to override the database.yml config values and mimic how AR works in rails. |
Bringing this up again. Really helpful for heroku deploys |
@jacquescrocker hi Jacques wondering if you have a very basic hello world rails app deployed to heroku - i'm having trouble getting heroku to connect to the sequel database and run some basic migrations. any pointers would be much appreciated. chrs |
I've got a basic one up and running on heroku, with instructions: https://github.com/BKSpurgeon/testing_in_sequel For anyone who comes across this thread in the future and is interested. Hope it helps! |
I would venture to say that the expectation nowadays is the opposite, i.e. that environment variables are overrides; because modifying source code files (like database.yml) from scripts is a lot more cumbersome than setting environment variables. And, Rails comes with a database.yml file, which precludes usage of DATABASE_URL, which is why I would say that sequel-rails should behave in the other way. What was the reason behind this decision? If there was none, wouldn't the fix be to just forward the plain URL to Sequel.connect, without the params?
to ::Sequel.connect normalized_config['url'] |
For containerized Rails applications, with this issue present, the only way to make |
ActiveRecord/Rails prefers the DATABASE_URL environment variable over the configuration in database.yml, if both are set the environment variable is used.
IMO sequel-rails should match this behaviour.
Being able to override the config via an environment variable is very useful for a number of reasons. It makes it easy to fire off a debugging session against a different database, for example I could load a db dump into a different database and then fire up a
DATABASE_URL=... rails server
and don't have to mess with the configuration, and don't have to throw away my dev database and can easily switch back.Another reason is that services like Heroku configure the database via this environment variable. When using their new CI service for example, it's pretty annoying to get the database connection to use the local database in development, but use the environment variable for CI.
The text was updated successfully, but these errors were encountered: