Doctrine Custom MariaDB Platform

Viewed 212

I've created CustomDbPlatform extending MySqlPlatform based on existing MariaDb1027Platform with custom getDefaultValueDeclarationSQL method. I can't extend MariaDbPlatform since it's a final class.

class CustomDbPlatform extends MySqlPlatform
{
    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;
    }

    public function getDefaultValueDeclarationSQL($column): string
    {
        if (isset($column['default'], $column['type'])) {
            $default = $column['default'];
            $type = $column['type'];

            if ($type instanceof DateTimePrecisionType && stripos($default, $this->getCurrentTimestampSQL()) !== false) {
                if (isset($column['length']) && $column['length'] > 0 && $column['length'] < 255) {
                    return ' DEFAULT ' . sprintf('%s(%d)', $this->getCurrentTimestampSQL(), $column['length']);

                }

                return ' DEFAULT ' . $this->getCurrentTimestampSQL();
            }
        }

        return parent::getDefaultValueDeclarationSQL($column);
    }
}

Unfortunately, during schema update Doctrine forces to update basically whole schema with new table column definitions. This problem is caused by MySqlSchemaManager which checks specifically for MariaDb1027Platform.

if ($this->_platform instanceof MariaDb1027Platform) {
        $columnDefault = $this->getMariaDb1027ColumnDefault($this->_platform, $tableColumn['default']);
    } else {
        $columnDefault = $tableColumn['default'];
    }

How can I make Doctrine to recognize my CustomDbPlatform as MariaDb1027Platform? Making custom SchemaManager seems to be an overkill.

Using

  • Symfony 4.4
  • Doctrine 2
  • MariaDB 10.3
1 Answers
Related