diff --git a/config/packages/dev/doctrine.yaml b/config/packages/dev/doctrine.yaml new file mode 100644 index 000000000..b2096c66b --- /dev/null +++ b/config/packages/dev/doctrine.yaml @@ -0,0 +1,5 @@ +doctrine: + dbal: + url: '%env(stripschema:DATABASE_URL)%' + server_version: 'mariadb-0.0.0' + driver_class: App\Doctrine\Driver diff --git a/src/Doctrine/Driver.php b/src/Doctrine/Driver.php new file mode 100644 index 000000000..a5027ff55 --- /dev/null +++ b/src/Doctrine/Driver.php @@ -0,0 +1,25 @@ + + * + * 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(); + } +} diff --git a/src/Doctrine/Platform.php b/src/Doctrine/Platform.php new file mode 100644 index 000000000..4f422b0f1 --- /dev/null +++ b/src/Doctrine/Platform.php @@ -0,0 +1,47 @@ + + * + * 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; + } +} diff --git a/src/Doctrine/TrimSchemaEnvVarProcessor.php b/src/Doctrine/TrimSchemaEnvVarProcessor.php new file mode 100644 index 000000000..34338941d --- /dev/null +++ b/src/Doctrine/TrimSchemaEnvVarProcessor.php @@ -0,0 +1,31 @@ + + * + * 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', + ]; + } +}