symfonyherokuproductionstagingcleardb

Manage Symfony App Heroku


I've a Symfony app on Heroku with ClearDb addons. I need to manage the app for test and prod. So I need two database: one for test and one for the production(principle);

I tryed the Heroku Pipeline, but when I promote the app from staging to production, the production app is connetted to staging db. How can solve ? How you manage it?

EDIT I discovered the mistake. I set the parameters via

$db = parse_url(getenv('CLEARDB_DATABASE_URL'));
$container->setParameter('database_host', $db['host']);

From a quick search for $container->setParameter I can see that this is a Symfony feature to interpolate values into code, however they mention the following warning in their docs:

NOTE: You can only set a parameter before the container is compiled: not at run-time. To learn more about compiling the container see Compiling the Container. https://symfony.com/doc/current/service_container/parameters.html#getting-and-setting-container-parameters-in-php

Heroku handle only symfony apps in prod env. So the stage app also have the environment var as "prod". How can I set parameters for different env? Or dynamically?

Thanks, AlterB


Solution

  • I've solved with the Environment Variables.

    I changed into app/config/config.yml this:

    doctrine:
        dbal:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
    

    with that

    doctrine:
        dbal:
            driver: pdo_mysql
            url: '%env(CLEARDB_DATABASE_URL)%'
    

    The app gets the db connection directly from Heroku Env. And it's done!