-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
add ability to override url with dsn params #1290
Conversation
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.
Hi!
👍 from me for the use-case.
This could also be used to powerParaTest: you could set the dbname
to main_test_%env(TEST_TOKEN)%
in config/packages/test/doctrine.yaml
. That would allow you to use your normal database connection params, but toggle the database name for parallel tests.
Cheers!
I'm also fine with idea, but I think we should push for this to be a default. Perhaps we should make it deprecated to not set this option to true and in doctrine bundle 4 remove it and just make this behavior default. I don't see a use case currently where it makes sense to define both ways to define database connection options. But that changes with this pr, that's why we should introduce such deprecation together with introducing this. |
or maybe this should be changed in DBAL so that specifying both an option explicitly and the URL makes the option win instead of the URL, removing the need to do such hack in the bundle. |
yep |
I was wondering about this too. Let's add those deprecations
That would also be awesome. We could do this PR, then see how this could be moved upstream so that - someday - the hackery in the |
c977887
to
9786913
Compare
I think the test failures are happening for some cases where the |
the remaining test failures do not appear to be caused by this PR as I see them in PR #1295 as well |
850b020
to
c869712
Compare
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.
- Adding note in UPGRADE-2.3.md required
- Adding docs in configuration.rst required
- Removal of deprecation-contracts required
- Fix for override_url: true in combination with URL and unspecified options that don't default to NULL required
Tests/DependencyInjection/Fixtures/config/yml/dbal_allow_url_override.yml
Show resolved
Hide resolved
92cb3a0
to
265e8e9
Compare
this should be ready for another review |
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.
Very minor comments!
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 ready to me 👍
|
||
$nestedConnections = ['shards', 'replicas', 'slaves']; | ||
|
||
foreach ($connectionDefaults as $defaultKey => $defaultValue) { |
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.
I don't understand why is this done. If I remove this block and revert removal of default values in Configuration.php, all tests pass. It should be clear from code why was this done this way.
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.
Follow up to our slack conversation and to bring everyone else up to speed:
If we set default values in the Configuration
- we have no way to determine if a value is an override or a default. https://github.com/doctrine/DoctrineBundle/pull/1290/files#diff-59ba6fdc91d16d6c28504e469b134f4bbf84e6b39d42c83d91652afe6015e1e7 asserts this behavior. If we set the defaults in the Configuration
, this test will now fail(host
would be localhost
rather than the overridden value).
Tests/DependencyInjection/Fixtures/config/yml/dbal_allow_url_override.yml
Outdated
Show resolved
Hide resolved
b3529fd
to
07fb095
Compare
@jrushlow Hey thanks for starting to fix this, but if you would like, I could fix all of the comments for you. Just please let me know in my comments if I am wrong in some of them. Especially removal of default values is questionable for me, but maybe you had a reason for that - in that case I would like to know about it. |
Thanks @ostrolucky - im going through the rest of this to try and get it wrapped up for today, but ill let you know if i run out of time (kids have a soccer game in a couple hours) / get stuck on something
We had to remove the defaults from the config otherwise we have no way of determining if a value for say Anywho, im looking at it now to see if there is a way we can do this w/o removing the defaults from the |
I was testing exactly this case locally actually. I modified the test case by setting host to |
4157a9f
to
d1bbcb8
Compare
ac71ef4
to
8747720
Compare
I've done some cleanup for you, let me know if you notice something suspicious in my changes. |
Everything looks good to me. Thanks @ostrolucky for the help on this! |
I'm proposing another approach in #1328 |
Note that I don't agree with the deprecation and that I'm proposing to revert it in #1328 |
@jrushlow What do you think about that? |
Use case:
If you define a connection
url
in Symfony using a realDATABASE_URL
env var for development, and you use the same server, but different database for tests - you have to override the entireDATABASE_URL
in yourconfig/packages/test/doctrine.yaml
file.This PR would allow you to override part of the
url
using any combination ofdbname
,host
,port
,user
, and/orpassword
. To preserve BC, we would add adoctrine.dbal.override_url
bool
configuration param.Example:
Assuming there is a
DATABASE_DSN
env var set tomysql://user:pass@host/main_database
, then in thetest
environment it would still usemysql://user:pass@host
but with themain_test
database.