Skip to content

Commit

Permalink
Resolve #362
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Dec 28, 2020
1 parent 7fa64d8 commit 64a171e
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/packages/dev/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
doctrine:
dbal:
url: '%env(stripschema:DATABASE_URL)%'
server_version: 'mariadb-0.0.0'
driver_class: App\Doctrine\Driver
25 changes: 25 additions & 0 deletions src/Doctrine/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the mangel.io project.
*
* (c) Florian Moser <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Doctrine;

use Doctrine\DBAL\Driver\PDOMySql;

class Driver extends PDOMySql\Driver
{
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new Platform();
}
}
47 changes: 47 additions & 0 deletions src/Doctrine/Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the mangel.io project.
*
* (c) Florian Moser <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Doctrine;

use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Types;

class Platform extends MySqlPlatform
{
/**
* {@inheritdoc}
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
$truncateSql = parent::getTruncateTableSQL($tableName, $cascade);

return 'SET foreign_key_checks = 0;'.$truncateSql.';SET foreign_key_checks = 1;';
}

// methods copied out of MariaDb1027Platform
public function getJsonTypeDeclarationSQL(array $column): string
{
return 'LONGTEXT';
}

protected function getReservedKeywordsClass(): string
{
return MariaDb102Keywords::class;
}

protected function initializeDoctrineTypeMappings(): void
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['json'] = Types::JSON;
}
}
31 changes: 31 additions & 0 deletions src/Doctrine/TrimSchemaEnvVarProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the mangel.io project.
*
* (c) Florian Moser <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\Doctrine;

use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;

class TrimSchemaEnvVarProcessor implements EnvVarProcessorInterface
{
public function getEnv(string $prefix, string $name, \Closure $getEnv)
{
$env = $getEnv($name);

return substr($env, strpos($env, '://') + 3);
}

public static function getProvidedTypes()
{
return [
'stripschema' => 'string',
];
}
}

0 comments on commit 64a171e

Please sign in to comment.