Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!