Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ final class SqliteGateway implements Gateway
*/
private const FATAL_ERROR_CODE = 7;

private const DB_INT_MAX = 2147483647;

/** @var array<string, int> */
private $lastInsertedIds = [];

Expand All @@ -27,7 +29,7 @@ public function getColumnNextIntegerValue(
string $sequenceName
): ?int {
$lastId = $this->lastInsertedIds[$sequenceName] ?? 0;
$nextId = (int)hrtime(true);
$nextId = (int)hrtime(true) % self::DB_INT_MAX;

// $lastId === $nextId shouldn't happen using high-resolution time, but better safe than sorry
return $this->lastInsertedIds[$sequenceName] = $lastId === $nextId ? $nextId + 1 : $nextId;
Expand Down