Skip to content

Commit 42600a6

Browse files
committed
Merge branch 'main' of github.com:utopia-php/database into internal-attributes-defaults
2 parents b23b8a8 + 2bd87ac commit 42600a6

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

src/Database/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ abstract public function deleteDocument(string $collection, string $id): bool;
747747
* Delete Documents
748748
*
749749
* @param string $collection
750-
* @param array<int> $sequences
750+
* @param array<string> $sequences
751751
* @param array<string> $permissionIds
752752
*
753753
* @return int

src/Database/Adapter/MariaDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public function createDocument(string $collection, Document $document): Document
905905

906906
$stmt->execute();
907907

908-
$document['$sequence'] = (int) $this->pdo->lastInsertId();
908+
$document['$sequence'] = $this->pdo->lastInsertId();
909909

910910
if (empty($document['$sequence'])) {
911911
throw new DatabaseException('Error creating document empty "$sequence"');
@@ -1656,7 +1656,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
16561656
unset($results[$index]['_uid']);
16571657
}
16581658
if (\array_key_exists('_id', $document)) {
1659-
$results[$index]['$sequence'] = (int) $document['_id'];
1659+
$results[$index]['$sequence'] = $document['_id'];
16601660
unset($results[$index]['_id']);
16611661
}
16621662
if (\array_key_exists('_tenant', $document)) {

src/Database/Adapter/Postgres.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ public function createDocument(string $collection, Document $document): Document
10281028

10291029
try {
10301030
$this->execute($stmt);
1031-
$lastInsertedId = (int) $this->getPDO()->lastInsertId();
1031+
$lastInsertedId = $this->getPDO()->lastInsertId();
10321032
// Sequence can be manually set as well
10331033
$document['$sequence'] ??= $lastInsertedId;
10341034

@@ -1541,7 +1541,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15411541
unset($results[$index]['_uid']);
15421542
}
15431543
if (\array_key_exists('_id', $document)) {
1544-
$results[$index]['$sequence'] = (int) $document['_id'];
1544+
$results[$index]['$sequence'] = $document['_id'];
15451545
unset($results[$index]['_id']);
15461546
}
15471547
if (\array_key_exists('_tenant', $document)) {

src/Database/Adapter/SQL.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function getDocument(string $collection, string $id, array $queries = [],
369369
$document = $document[0];
370370

371371
if (\array_key_exists('_id', $document)) {
372-
$document['$sequence'] = (int) $document['_id'];
372+
$document['$sequence'] = $document['_id'];
373373
unset($document['_id']);
374374
}
375375
if (\array_key_exists('_uid', $document)) {
@@ -466,7 +466,7 @@ public function updateDocuments(string $collection, Document $updates, array $do
466466
}
467467

468468
foreach ($sequences as $id => $value) {
469-
$stmt->bindValue(":_id_{$id}", $value, \PDO::PARAM_INT);
469+
$stmt->bindValue(":_id_{$id}", $value);
470470
}
471471

472472
$attributeIndex = 0;
@@ -648,7 +648,7 @@ public function updateDocuments(string $collection, Document $updates, array $do
648648
* Delete Documents
649649
*
650650
* @param string $collection
651-
* @param array<int> $sequences
651+
* @param array<string> $sequences
652652
* @param array<string> $permissionIds
653653
*
654654
* @return int
@@ -1913,7 +1913,7 @@ public function createDocuments(string $collection, array $documents): array
19131913

19141914
foreach ($documents as $document) {
19151915
if (isset($sequences[$document->getId()])) {
1916-
$document['$sequence'] = (int) $sequences[$document->getId()];
1916+
$document['$sequence'] = $sequences[$document->getId()];
19171917
}
19181918
}
19191919
} catch (PDOException $e) {

src/Database/Adapter/SQLite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public function createDocument(string $collection, Document $document): Document
609609
$statment->execute();
610610
$last = $statment->fetch();
611611

612-
$document['$sequence'] = (int) $last['id'];
612+
$document['$sequence'] = $last['id'];
613613

614614
if (isset($stmtPermissions)) {
615615
$stmtPermissions->execute();

src/Database/Database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class Database
165165
],
166166
[
167167
'$id' => '$sequence',
168-
'type' => self::VAR_INTEGER,
169-
'size' => 8,
168+
'type' => self::VAR_STRING,
169+
'size' => Database::LENGTH_KEY,
170170
'required' => true,
171171
'signed' => true,
172172
'array' => false,

src/Database/Document.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public function getId(): string
6262
}
6363

6464
/**
65-
* @return int
65+
* @return string
6666
*/
67-
public function getSequence(): int
67+
public function getSequence(): string
6868
{
69-
return $this->getAttribute('$sequence', 0);
69+
return $this->getAttribute('$sequence', '');
7070
}
7171

7272
/**

src/Database/Validator/Queries/Documents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
$attributes[] = new Document([
3939
'$id' => '$sequence',
4040
'key' => '$sequence',
41-
'type' => Database::VAR_INTEGER,
41+
'type' => Database::VAR_STRING,
4242
'array' => false,
4343
]);
4444
$attributes[] = new Document([

src/Database/Validator/Structure.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Structure extends Validator
3232
],
3333
[
3434
'$id' => '$sequence',
35-
'type' => Database::VAR_INTEGER,
36-
'size' => 8,
35+
'type' => Database::VAR_STRING,
36+
'size' => 255,
3737
'required' => false,
3838
'signed' => true,
3939
'array' => false,

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testCreateDocument(): Document
9393
// Test create document with manual internal id
9494
$manualIdDocument = $database->createDocument('documents', new Document([
9595
'$id' => '56000',
96-
'$sequence' => 56000,
96+
'$sequence' => '56000',
9797
'$permissions' => [
9898
Permission::read(Role::any()),
9999
Permission::read(Role::user(ID::custom('1'))),
@@ -292,7 +292,7 @@ public function testCreateDocumentsWithAutoIncrement(): void
292292

293293
for ($i = $sequence; $i <= ($sequence + $count); $i++) {
294294
$documents[] = new Document([
295-
'$sequence' => $i,
295+
'$sequence' => (string)$i,
296296
'$permissions' => [
297297
Permission::read(Role::any()),
298298
Permission::create(Role::any()),
@@ -363,7 +363,7 @@ public function testCreateDocumentsWithDifferentAttributes(): void
363363
$documents = [
364364
new Document([
365365
'$id' => 'third',
366-
'$sequence' => 3,
366+
'$sequence' => 'third',
367367
'string' => 'text📝',
368368
]),
369369
new Document([
@@ -1778,9 +1778,9 @@ public function testFindByID(): void
17781778
* @depends testFind
17791779
* @param array<string, mixed> $data
17801780
* @return void
1781-
* @throws DatabaseException
1781+
* @throws \Utopia\Database\Exception
17821782
*/
1783-
public function testFindBySequence(array $data): void
1783+
public function testFindByInternalID(array $data): void
17841784
{
17851785
/** @var Database $database */
17861786
$database = static::getDatabase();
@@ -4279,7 +4279,7 @@ public function testExceptionCaseInsensitiveDuplicate(Document $document): Docum
42794279
$database = static::getDatabase();
42804280

42814281
$document->setAttribute('$id', 'caseSensitive');
4282-
$document->setAttribute('$sequence', 200);
4282+
$document->setAttribute('$sequence', '200');
42834283
$database->createDocument($document->getCollection(), $document);
42844284

42854285
$document->setAttribute('$id', 'CaseSensitive');

0 commit comments

Comments
 (0)