-
Notifications
You must be signed in to change notification settings - Fork 21.6k
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
db:test:purge fails when db is set with DATABASE_URL only #24294
Comments
Reproducible for latest (878c2bb) master |
I will work on it. |
This issue appears to occur on 4.2 as well. Since this issue is not a regression in 5.0, it can be resolved in 5.0.1 but does not need to block the initial release. |
The problem is, that From what I have seen, there are at least two solutions: Second approach would be to just change the config in Rake task: I think the latter would be much simpler. Any opinions? |
Hi @prathamesh-sonpatki still working on this? Was looking on related code and fix for this. |
Yes, I am working on this. |
@Kukunin could you please help me with reproducing this? |
@prathamesh-sonpatki ping me on the PR resolving this issue, I would like to take a look. |
@Kukunin @arthurnn This is a tricky issue. The database test rake tasks don't rely on the ENV for manipulating test database. They directly read from the "test" configuration specification. Additionally, DATABASE_URL gets applied to the current ENV when it gets resolved. When we are using the test rake tasks within a Rails app, the environment used by the connection handling logic is "development" unless specified by So the DATABASE_URL gets resolved to only the "development" environment and fetching it for "test" environment fails. IMO resolving DATABASE_URL to test environment is bad because it means that your database gets manipulated when running the tests. This defeats the purpose of having the "Rails" way of separate databases for development, test and production. In this, we can update the documentation and raise a friendly error saying that Let me know your thoughts and I can work on a PR for this approach. |
@prathamesh-sonpatki I see what's the problem. Actually I agree with you. If one is going to run Rails application in test env with database set via Otherwise, replace |
This not a good option. We can document this case with the DATABASE_URL and also raise helpful error message for missing test database configuration. |
…tabase is not configured - Inspiration for this change comes from rails#24294 where `db:test:purge` fails when used with DATABASE_URL. - This is because the database rake tasks don't depend on RAILS_ENV and that's why DATABASE_URL gets applied to development environment by default when running these tasks. - This means that the "test" database configuration is not present but while running test database rake tasks we expect it to be present. - This commit will raise a helpful error when "test" database configuration is not present, gently reminding users that they need to add it before running the test database rake tasks.
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
It's identical to this issue #13742, but for Rails 5.
Steps to reproduce
Create application, set database with DATABASE_URL only, but without
config/database.yml
config file.Run
bundle exec rake db:test:load
Expected behavior
Command works successfully, without any error, with using DB config from DATABASE_URL env variable.
Actual behavior
System configuration
Rails version:
5.0.0.beta3
Ruby version:
2.3.0
The text was updated successfully, but these errors were encountered: