3

I'm using NDBCLUSTER engine in a MySQL DB. I've added a class for wrapping Connection and adding the engine option:

namespace AppBundle\DBAL;

use Doctrine\DBAL\Connection as BaseConnection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;

class Connection extends BaseConnection
{
    public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null)
    {

        if (isset($params['driverOptions']['engine'])) {
            $params['defaultTableOptions']['engine'] = $params['driverOptions']['engine'];
        }

        return parent::__construct($params, $driver, $config, $eventManager);
    }
}

I define the engine option in the config.yml file:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                wrapper_class: AppBundle\DBAL\Connection
                options:
                    engine: NDBCLUSTER
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    AppBundle:  ~

Then, if I execute php app/console doctrine:migrations:diff the NDBCLUSTER engine is added to the CREATE statements. However, the foreign keys are added too, and NDBCLUSTER does not accept foreign keys. Is there any way to disable the foreign keys (I mean, not writing them in the migration files)?

Manolo
  • 24,020
  • 20
  • 85
  • 130

1 Answers1

2

I disabled the foreign keys by implementing my own platform_service for that connection:

namespace AcmeBundle\Doctrine;
use Doctrine\DBAL\Platforms\MySQL57Platform;

class CustomMySQLPlatform extends MySQL57Platform
{

    public function supportsForeignKeyConstraints()
    {
        return false;
    }

    public function supportsForeignKeyOnUpdate()
    {
        return false;
    }
}

Service definition in services.yml:

    acme.dbal.service.custom_mysql_platform:
        class: AcmeBundle\Doctrine\CustomMySQLPlatform

Doctrine DBAL definition in config.yml:

doctrine:
    dbal:
        connections:
            default:
                ....
                platform_service: acme.dbal.service.custom_mysql_platform
enricog
  • 4,226
  • 5
  • 35
  • 54