Skip to content

generateUUIDv4() with query builder #36

@andrelec1

Description

@andrelec1

I try to define a column with default value = generateUUIDv4()

i try $newTable->addColumn('uuid', 'string', ['default' => 'generateUUIDv4()']);
but the value is string not the function ...

so for the moment i use a little trick like this:

public function up(Schema $schema) : void
    {
        /** @var Connection */
        $conn = $this->container->get('doctrine.dbal.clickhouse_connection');
        /** @var Schema */
        $fromSchema = new Schema();
        /** @var Schema */
        $toSchema = clone $fromSchema;

        $newTable = $toSchema->createTable('probe_datum');
        $newTable->addOption('engine', 'MergeTree');

        $newTable->addColumn('uuid', 'string', ['default' => 'generateUUIDv4()']);
        $newTable->addColumn('datetime_value', 'datetime');
        $newTable->addColumn('value', 'float');
        $newTable->addColumn('probe_id', 'integer');

        $newTable->setPrimaryKey(['uuid', 'datetime_value', 'probe_id']);

        $sqlArray = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());

        foreach ($sqlArray as $sql) {
            $hackSql = str_replace('\'generateUUIDv4()\'', 'generateUUIDv4()', $sql);
            $conn->exec($hackSql);
        }
    }

how can i do this properly ?

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