Reputation: 1802
Our MySQL databases have enum fields which are usually converted to strings in the app/config/config.yml
file:
doctrine:
dbal:
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
However when running migrations we use a specific db-configuration file such as:
app/console doctrine:migrations:migrate --db-configuration=app/config/migrations/db.php
Where db.php
file is:
<?php
return array(
'dbname' => 'database',
'user' => 'username',
'password' => 'password',
'host' => 'localhost',
'driver' => 'pdo_mysql',
'charset' => 'utf8',
'mapping_types' => array(
'enum' => 'string'
)
);
The mapping_types parameter is ignored, resulting in:
Migration 0000000000 failed during Pre-Checks. Error Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
I'm struggling to find any documentation on using the --db-configuration
option (hence why it's not in yml format - doctrine always complains "The connection file has to return an array with database configuration parameters.").
Is there a different syntax for converting enums in php format or another approach to take?
Upvotes: 0
Views: 1841
Reputation: 60413
That option is inherited from the Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand
and so doesn't interact with the Symfony2 infrastructure, which is where the mapping_types
configuration magic happens. This needs to be a PHP array of params (or an included PHP file that returns an array) - loading XML/YAML/etc. isn't directly supported.
The only options definable there are for the DBAL connection. Types, while related, are not actually part of the connection. Instead they are registered statically within the Type subsystem and then hooked in to the connection via the Platform. This happens somewhere in the Symfony Configuration process via DI. So in order to make use of it you would need to define it in a symfony-land configuration file like a config_migration.yml
. You could then still use the db-configuration
option to inject different connection parameters but you would still have the mapping_types
processed in the Symfony stack.
If you dig in there is likely a way to do this in a more elegant fashion by extending the The migration commands or other parts of the DoctrineMigrationsBundle
but using an environment configuration file would probably be the low-hanging fruit approach.
Upvotes: 1