Roubi
Roubi

Reputation: 2106

Override mapping_types section in doctrine config_dev with Symfony

I'm using this doctrine config for prod environment:

doctrine:
    dbal:
        default_connection: app_connection
        connections: 
            app_connection:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types:
                    bit: boolean

But when working locally, I always have to delete the mapping_types:bit: boolean part in order to be able to drop and create my database. (Otherwise I get error 'unknown database')

So I thought I would override the doctrine config in the config_dev.yml file by copying it and not writing the mapping_types section, but it's not working. If I don't delete it in the config.yml, I keep getting the error.

I guess I could use a config_dev file that would not import the config file, but I was wondering if there was an effective way to override the 'mapping_types' section.

Upvotes: 2

Views: 760

Answers (1)

Matteo
Matteo

Reputation: 39400

You could use a parameters field (from the parameters.yml files) in order to configure in different machine. As example, you could specify in the config.yml files:

doctrine:
    dbal:
        default_connection: app_connection
        connections: 
            app_connection:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types: "%database_mapping_types%"

And configure in your parameters.yml of the production server:

parameters.yml

  database_mapping_types: {bit: boolean}

And configure in your parameters.yml of the local server:

parameters.yml

  database_mapping_types: ~

obviously set a default in the parameter.yml.dist as example:

parameters.yml.dist

  database_mapping_types: ~

EDIT:

Of course, you can specify a different configuration for prod environment instead of the dev as follow:

config_dev.yml

doctrine:
    dbal:
        default_connection: app_connection
        connections: 
            app_connection:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types: ~

And in the prod environment you can override the key you need as follow:

config_prod.yml

doctrine:
    dbal:
        default_connection: app_connection
        connections: 
            app_connection:
              mapping_types:
                  bit: boolean

Hope this help

Upvotes: 2

Related Questions