I don´t understand why user is allowed to create a dev database while he is not to create a test one.
At the root of my project :
docker-compose
db:
image: mysql:5.7
environment:
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ALLOW_EMPTY_PASSWORD=true
ports:
- '127.0.0.1:3306:3306'
volumes:
- 'db:/var/lib/mysql'
.env :
DB_NAME=mydb
DB_ROOT_PASSWORD=root
DB_USER=dev
DB_PASSWORD=dev
In the app directory, I tried following scenarios :
Scenario 1 :
Without .env.test and an overriden url from dev to test
doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
driver: pdo_mysql
server_version: "%env(DB_VERSION)%"
test/doctrine.yaml :
doctrine:
dbal:
dbname_suffix: _test
profiling: true
.env :
APP_ENV=dev
DB_VERSION=5.7
DATABASE_URL=mysql://dev:dev@db:3306/mydb
Scenario 2 :
With the same config in both dev and test environments, except the database name
doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
driver: pdo_mysql
server_version: "%env(DB_VERSION)%"
test/doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
profiling: true
.env :
APP_ENV=dev
DB_VERSION=5.7
DATABASE_URL=mysql://dev:dev@db:3306/mydb
.env.test :
APP_ENV=test
DB_VERSION=5.7
DATABASE_URL=mysql://dev:dev@db:3306/mydb_test
Scenario 3 :
With different variables in different environments
doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
driver: pdo_mysql
server_version: "%env(DB_VERSION)%"
test/doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_TEST_URL)%'
profiling: true
.env :
APP_ENV=dev
DB_VERSION=5.7
DATABASE_URL=mysql://dev:dev@db:3306/mydb
.env.test :
APP_ENV=test
DB_VERSION=5.7
DATABASE_TEST_URL=mysql://dev:dev@db:3306/mydb_test
Problem :
docker compose run --rm myContainer doctrine:database:create
: the main database is created without problem
docker compose run --rm myContainer doctrine:database:create --env=test
: I always get the following error :
Could not create database
mydb_test
for connection named default An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1044 Access denied for user 'dev'@'%' to database 'mydb_test'`