Max Schindler
Max Schindler

Reputation: 380

Doctrine MasterSlaveConnection with empty env-vars

# doctrine.yaml
parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_MASTER_URL): ''
    env(DATABASE_SLAVE1_URL): ''

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver: pdo_mysql
                url: '%env(resolve:DATABASE_MASTER_URL)%'
                server_version: '5.7'
                charset: utf8mb4
                default_table_options:
                    charset: utf8mb4
                    collate: utf8mb4_unicode_ci
                slaves:
                    slave1:
                        url: '%env(resolve:DATABASE_MASTER_URL)%'
                        charset: utf8mb4

When i run php bin/console cache:clear i get this error:

The options 'driver' or 'driverClass' are mandatory if no PDO instance is given to DriverManager::getConnection().

This happens, when we do not have overwritten the env vars DATABASE_MASTER_URL & DATABASE_SLAVE1_URL. In on step of our gitlab pipeline, where do not have those values at hand, we need to clear / warmup the cache.

The thing that is funny here: If i remove the definition for slaves, everything works fine. It only happens in a scenario where we define slaves.

ADDITIONAL INFORMATION 1 The WrapperClass "MasterSlaveConnection" does exactly what is need, but only to late. It takes the "driver" from the config and injects it into master and the slave nodes.

But this happens AFTER DriverManager::parseDatabaseUrlScheme is called.

So either 1) I am doing something wrong here and there is room for improvement in documentation or 2) there is a bug

Upvotes: 1

Views: 479

Answers (0)

Related Questions