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

generateUUIDv4() with query builder #36

Open
andrelec1 opened this issue Feb 5, 2020 · 0 comments
Open

generateUUIDv4() with query builder #36

andrelec1 opened this issue Feb 5, 2020 · 0 comments

Comments

@andrelec1
Copy link

andrelec1 commented Feb 5, 2020

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 ?

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

1 participant