Reputation: 8921
I recently started working with Symfony 4.
While developing I like to have two different environments: one for dev (surfing the site with some fake data that we have on fixtures) and one for testing where I execute behat tests that reset the database on each test.
In previous versions of symfony I just had two different databases: mysite_dev and mysite_test and two parameters files (parameters_dev.yml and parameters_test.yml) with the proper database configuration.
But with Symfony 4 and the .env configuration file I don't see the way of doing this. I don't see any way of having two sets of ddbb params and be able to run php bin/console doctrine:schema:update --env=test or php bin/console doctrine:schema:update --env=dev.
Any ideas? thanks!
Upvotes: 2
Views: 2512
Reputation: 1236
how about using different url variables in your config?
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL_DEV)%'
# config/packages/test/doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL_TEST)%'
also consider this comment from the default config file
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_URL): ''
Upvotes: 2
Reputation: 29932
It's quite easy: your commands can still reference an environment with --env
and everytime you need to switch from one environment to other you have basically two choices:
.env
file.env
as described hereUpvotes: 0