Skip to content

Commit b55d806

Browse files
authored
Merge pull request #609 from utopia-php/primary-bigint
Primary bigint
2 parents e68f2e3 + 6c5b7df commit b55d806

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function createCollection(string $name, array $attributes = [], array $in
155155

156156
$collection = "
157157
CREATE TABLE {$this->getSQLTable($id)} (
158-
_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
158+
_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
159159
_uid VARCHAR(255) NOT NULL,
160160
_createdAt DATETIME(3) DEFAULT NULL,
161161
_updatedAt DATETIME(3) DEFAULT NULL,
@@ -186,7 +186,7 @@ public function createCollection(string $name, array $attributes = [], array $in
186186

187187
$permissions = "
188188
CREATE TABLE {$this->getSQLTable($id . '_perms')} (
189-
_id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
189+
_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
190190
_type VARCHAR(12) NOT NULL,
191191
_permission VARCHAR(255) NOT NULL,
192192
_document VARCHAR(255) NOT NULL,

src/Database/Adapter/Postgres.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ public function createCollection(string $name, array $attributes = [], array $in
232232
$sqlTenant = $this->sharedTables ? '_tenant INTEGER DEFAULT NULL,' : '';
233233
$collection = "
234234
CREATE TABLE {$this->getSQLTable($id)} (
235-
_id SERIAL NOT NULL,
235+
_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
236236
_uid VARCHAR(255) NOT NULL,
237237
" . $sqlTenant . "
238238
\"_createdAt\" TIMESTAMP(3) DEFAULT NULL,
239239
\"_updatedAt\" TIMESTAMP(3) DEFAULT NULL,
240-
_permissions TEXT DEFAULT NULL,
241240
" . \implode(' ', $attributeStrings) . "
242-
PRIMARY KEY (_id)
241+
_permissions TEXT DEFAULT NULL
243242
);
244243
";
245244

@@ -262,13 +261,12 @@ public function createCollection(string $name, array $attributes = [], array $in
262261

263262
$permissions = "
264263
CREATE TABLE {$this->getSQLTable($id . '_perms')} (
265-
_id SERIAL NOT NULL,
264+
_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
266265
_tenant INTEGER DEFAULT NULL,
267266
_type VARCHAR(12) NOT NULL,
268267
_permission VARCHAR(255) NOT NULL,
269-
_document VARCHAR(255) NOT NULL,
270-
PRIMARY KEY (_id)
271-
);
268+
_document VARCHAR(255) NOT NULL
269+
);
272270
";
273271

274272
if ($this->sharedTables) {

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@
2222

2323
trait DocumentTests
2424
{
25+
public function testBigintSequence(): void
26+
{
27+
/** @var Database $database */
28+
$database = static::getDatabase();
29+
30+
$database->createCollection(__FUNCTION__);
31+
32+
$sequence = 5_000_000_000_000_000;
33+
34+
$document = $database->createDocument(__FUNCTION__, new Document([
35+
'$sequence' => (string)$sequence,
36+
'$permissions' => [
37+
Permission::read(Role::any()),
38+
],
39+
]));
40+
41+
$this->assertEquals((string)$sequence, $document->getSequence());
42+
43+
$document = $database->getDocument(__FUNCTION__, $document->getId());
44+
$this->assertEquals((string)$sequence, $document->getSequence());
45+
46+
$document = $database->findOne(__FUNCTION__, [Query::equal('$sequence', [(string)$sequence])]);
47+
$this->assertEquals((string)$sequence, $document->getSequence());
48+
}
49+
2550
public function testCreateDocument(): Document
2651
{
2752
/** @var Database $database */

0 commit comments

Comments
 (0)