Skip to content
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

[Proposal] Simplify the default configuration of DoctrineBundle #18

Closed
javiereguiluz opened this issue Apr 3, 2017 · 2 comments
Closed

Comments

@javiereguiluz
Copy link
Member

This is the default config provided by Symfony Flex:

###> doctrine/doctrine-bundle ###
DB_DRIVER=pdo_mysql
DB_HOST=127.0.0.1
DB_PORT=
DB_NAME=symfony
DB_USER=root
DB_PASSWORD=
###< doctrine/doctrine-bundle ###
# /etc/packages/doctrine.yaml
doctrine:
    dbal:
        driver: "%env(DB_DRIVER)%"
        host: "%env(DB_HOST)%"
        port: "%env(DB_PORT)%"
        dbname: "%env(DB_NAME)%"
        user: "%env(DB_USER)%"
        password: "%env(DB_PASSWORD)%"
    # ...

But maybe now it's the perfect time to switch to the simpler and more modern DSN-based alternative (like we do in the Symfony Demo app: https://github.com/symfony/symfony-demo/blob/master/app/config/parameters.yml.dist#L20). The perceived complexity is reduced significantly:

###> doctrine/doctrine-bundle ###
DB_URL='mysql://root@127.0.0.1:3306/symfony'
###< doctrine/doctrine-bundle ###
# /etc/packages/doctrine.yaml
doctrine:
    dbal:
        url: "%env(DB_URL)%"
    # ...

Another improvement of DSN-based config is that switching from a database to another is easier. For example: switching to SQLite is as easy as changing the value of DB_URL. Before you had to comment/uncomment config options in /etc/packages/doctrine.yml:

###> doctrine/doctrine-bundle ###
DB_URL='sqlite:///%kernel.root_dir%/../var/data/symfony.sqlite'
###< doctrine/doctrine-bundle ###
@fabpot
Copy link
Member

fabpot commented Apr 3, 2017

I kept the "old" way because changing just a couple of parameters like the password or the db name seems easier with several vars. But we can definitely switch to a simple DSN (which should then be done for Swiftmailer as well for consistency).

@fabpot
Copy link
Member

fabpot commented Apr 6, 2017

After thinking about this one, I'm sold. It's indeed much better. I've updated the recipes accordingly.

@fabpot fabpot closed this as completed Apr 6, 2017
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

No branches or pull requests

2 participants