Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
Doctrine Custom MariaDB Platform

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
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If you want to extend MariaDb1027Platform, the only way is:

  1. copy the platform class file from https://github.com/doctrine/dbal/blob/3.1.x/src/Platforms/MariaDb1027Platform.php ,
  2. place is into your project
  3. remove the final kw
  4. load this file before the class is autoloaded from DBAL lib - you can use composer autoload files section

Also, I have created PR https://github.com/doctrine/dbal/pull/4909 to see if the maintainers want to support this officially.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda