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
If you want to extend MariaDb1027Platform, the only way is:
final kwfiles sectionAlso, I have created PR https://github.com/doctrine/dbal/pull/4909 to see if the maintainers want to support this officially.