Open andrelec1 opened 4 years ago
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 ...
$newTable->addColumn('uuid', 'string', ['default' => 'generateUUIDv4()']);
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 ?
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:
how can i do this properly ?