Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CHARACTER SET keyword is split with a new line #149

Open
Menelion opened this issue Jan 9, 2025 · 1 comment
Open

The CHARACTER SET keyword is split with a new line #149

Menelion opened this issue Jan 9, 2025 · 1 comment

Comments

@Menelion
Copy link

Menelion commented Jan 9, 2025

Bug Report

Q A
Version 1.5.1
Previous Version if the bug is a regression N/A

Summary

Whenever a Doctrine migration is created with --formatted option, i.e., SQLFormatter is used under the hood, the DEFAULT CHARACTER SET statement is formatted in quite a bizarre way, see steps to reproduce.
I'm using MariaDB 11.2.2 on this machine.

Current behavior

Now it's like this for some reason:

          [...]
          PRIMARY KEY(id)
        ) DEFAULT CHARACTER
        SET
          utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'

Expected behavior

I would expect rather:

          [...]
          PRIMARY KEY(id)
        )
        DEFAULT CHARACTER SET utf8mb4
        COLLATE `utf8mb4_unicode_ci`
        ENGINE = InnoDB'

How to reproduce

Basically, make a migration with doctrine:migrations:diff --formatted or, if you are like me into Symfony, with make:migration --formatted. Here's one full migration for reference:

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250109223941 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Created languages table';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE languages (
          id INT AUTO_INCREMENT NOT NULL,
          position SMALLINT UNSIGNED NOT NULL,
          code VARCHAR(20) NOT NULL,
          english_name VARCHAR(100) NOT NULL,
          native_name VARCHAR(100) NOT NULL,
          PRIMARY KEY(id)
        ) DEFAULT CHARACTER
        SET
          utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE languages');
    }
}

I tried to dig in deeper to understand how to fix that, but so far I probably spent too little time on it, have no idea how it can be fixed appropriately.

@mvorisek
Copy link
Contributor

This library does not intend to parse full SQL grammar.

Both CHARACTER, SET are reserved keywords and per MySQL https://dev.mysql.com/doc/refman/8.4/en/create-table.html grammar there cannot be anything in between, the SET can be "weakened", ie. not assumed to be an isolated SET keyword used frequently in UPDATE ... SET ..., when CHARACTER is before the SET keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants