Skip to content

Commit

Permalink
Merge pull request #67 from vierge-noire/cake3_next
Browse files Browse the repository at this point in the history
Postgres update merged on cake_3
  • Loading branch information
pabloelcolombiano authored Apr 15, 2021
2 parents 376a650 + eabd1ff commit f841515
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Factory/DataCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public function generateRandomPrimaryKey(string $columnType)
{
switch ($columnType) {
case 'uuid':
case 'string':
$res = $this->getFactory()->getFaker()->uuid;
break;
case 'biginteger':
Expand Down Expand Up @@ -479,9 +480,13 @@ private function updatePostgresSequence(array $primaryKeys)
$tableName = $this->getFactory()->getRootTableRegistry()->getTable();

foreach ($primaryKeys as $pk => $offset) {
$this->getFactory()->getRootTableRegistry()->getConnection()->execute(
"SELECT setval('$tableName". "_$pk" . "_seq', $offset);"
);
$seq = $this->getFactory()->getRootTableRegistry()->getConnection()->execute("
SELECT pg_get_serial_sequence('$tableName','$pk')")->fetchAll()[0][0];
if ($seq !== null) {
$this->getFactory()->getRootTableRegistry()->getConnection()->execute(
"SELECT setval('$seq', $offset);"
);
}
}
}
}
Expand Down

0 comments on commit f841515

Please sign in to comment.