Skip to content

[ClickHouseSchemaManager] \FOD\DBALClickHouse\ClickHouseSchemaManager::selectTableNames throws exception when execute d:m:diff command #73

@VitekSkrip

Description

@VitekSkrip

I tried to describe the orm entity:

<?php

declare(strict_types=1);

namespace App\Context\Example\Infrastructure\ORM\Entity;

use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use FOD\DBALClickHouse\Types\ArrayDateTimeType;
use FOD\DBALClickHouse\Types\BigIntType;
use Pusk\CommonBundle\Domain\ValueObject\UUID;
use Pusk\CommonBundle\Infrastructure\ORM\Column\Generator\UUIDGenerator;
use Pusk\CommonBundle\Infrastructure\ORM\Column\Type\UUIDType;
use Pusk\CommonBundle\Infrastructure\ORM\Entity\ORMEntity;
use App\Context\Example\Infrastructure\ORM\Repository\ORMExampleRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\CustomIdGenerator;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;

#[Entity(repositoryClass: ORMExampleRepository::class)]
#[Table(name: 'examples')]
class ORMExample implements ORMEntity
{
    #[Id]
    #[Column]
    private int $uuid;

    #[Column(type: Types::BOOLEAN)]
    private bool $name;

    public function getUuid(): int
    {
        return $this->uuid;
    }

    public function setUuid(int $uuid): ORMExample
    {
        $this->uuid = $uuid;
        return $this;
    }

    public function getName(): bool
    {
        return $this->name;
    }

    public function setName(bool $name): self
    {
        $this->name = $name;

        return $this;
    }
}

And want to create migration by command: php bin/console d:m:diff --from-empty-schema

And get this exception:

07:52:10 CRITICAL  [console] Error thrown while running command "'d:m:diff'". Message: "An exception occurred while executing a query: " ["exception" => Doctrine\DBAL\Exception\DriverException^ { …},"command" => "'d:m:diff'","message" => "An exception occurred while executing a query: "]

In ClickHouseExceptionConverter.php line 26:
                                                  
  An exception occurred while executing a query:  
                                                  

In ClickHouseStatement.php line 132:
                                                   
  [FOD\DBALClickHouse\Driver\Exception\Exception]  
                                                   

In Statement.php line 179:
                                                                                                                                                                                                                                                  
  Cannot convert string BASE TABLE to type UInt8: while executing 'FUNCTION notEquals(multiIf(is_temporary, 4, like(engine, '%View'), 2, like(engine, 'System%'), 5, equals(has_own_data, 0), 3, 1) : 19, 'BASE TABLE' : 13) -> notEquals(multiI  
  f(is_temporary, 4, like(engine, '%View'), 2, like(engine, 'System%'), 5, equals(has_own_data, 0), 3, 1), 'BASE TABLE') UInt8 : 20'. (TYPE_MISMATCH)                                                                                             
  IN:SELECT table_name                                                                                                                                                                                                                            
  FROM INFORMATION_SCHEMA.TABLES                                                                                                                                                                                                                  
  WHERE  table_schema = 'clickhouse_test_service' AND table_type != 'BASE TABLE' FORMAT JSON            

Then i reformatted the following code:

from

protected function selectTableNames(string $databaseName): Result
    {
        return $this->connection->executeQuery(
            <<<'SQL'
            SELECT table_name
            FROM INFORMATION_SCHEMA.TABLES
            WHERE  table_schema = ? AND table_type != 'BASE TABLE'
            SQL,
            [$databaseName]
        );
    }

to

protected function selectTableNames(string $databaseName): Result
    {
        return $this->connection->executeQuery(
            <<<'SQL'
            SELECT table_name
            FROM INFORMATION_SCHEMA.TABLES
            WHERE  table_schema = ?
            SQL,
            [$databaseName]
        );
    }

it works!

<?php

declare(strict_types=1);

namespace Migration;

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

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20240927080131 extends AbstractMigration
{
    public function isTransactional(): bool
    {
        return false;
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE TABLE examples (EventDate Date DEFAULT today(), uuid Int32, name UInt8) ENGINE = ReplacingMergeTree(EventDate, (uuid), 8192)');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP TABLE examples');
    }
}

Note, that all migrations must return false in the isTransactional method, because ClickHouse does not support transactions

Conclusion: I guess \FOD\DBALClickHouse\ClickHouseSchemaManager::selectTableNames does not work as expected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions