Skip to content

Commit 5b34785

Browse files
index, attribute filters, typo updates
1 parent 29f4cfe commit 5b34785

5 files changed

Lines changed: 17 additions & 29 deletions

File tree

src/Database/Database.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Database
7373
...self::SPATIAL_TYPES,
7474
self::VAR_VECTOR,
7575
self::VAR_OBJECT,
76+
self::VAR_DATETIME
7677
];
7778

7879
// Index Types
@@ -2579,7 +2580,8 @@ public function updateAttribute(string $collection, string $id, ?string $type =
25792580
self::VAR_FLOAT,
25802581
self::VAR_BOOLEAN,
25812582
self::VAR_DATETIME,
2582-
self::VAR_RELATIONSHIP . ', ' . self::VAR_OBJECT
2583+
self::VAR_RELATIONSHIP,
2584+
self::VAR_OBJECT
25832585
];
25842586
if ($this->adapter->getSupportForVectors()) {
25852587
$supportedTypes[] = self::VAR_VECTOR;
@@ -3617,27 +3619,6 @@ public function createIndex(string $collection, string $id, string $type, array
36173619
}
36183620
}
36193621

3620-
if ($type === self::INDEX_OBJECT) {
3621-
if (count($attributes) !== 1) {
3622-
throw new IndexException('Object index can be created on a single object attribute');
3623-
}
3624-
3625-
foreach ($attributes as $attr) {
3626-
if (!isset($indexAttributesWithTypes[$attr])) {
3627-
throw new IndexException('Attribute "' . $attr . '" not found in collection');
3628-
}
3629-
3630-
$attributeType = $indexAttributesWithTypes[$attr];
3631-
if ($attributeType !== self::VAR_OBJECT) {
3632-
throw new IndexException('Object index can only be created on object attributes. Attribute "' . $attr . '" is of type "' . $attributeType . '"');
3633-
}
3634-
}
3635-
3636-
if (!empty($orders)) {
3637-
throw new IndexException('Object indexes do not support explicit orders. Remove the orders to create this index.');
3638-
}
3639-
}
3640-
36413622
$index = new Document([
36423623
'$id' => ID::custom($id),
36433624
'key' => $id,

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,16 +1750,23 @@ public function testCreateDatetime(): void
17501750
}
17511751
}
17521752

1753-
public function testCreateDateTimeAttributeFailure(): void
1753+
public function testCreateDatetimeAddingAutoFilter(): void
17541754
{
17551755
/** @var Database $database */
17561756
$database = static::getDatabase();
17571757

1758-
$database->createCollection('datetime_fail');
1758+
$database->createCollection('datetime_auto_filter');
17591759

1760-
/** Test for FAILURE */
17611760
$this->expectException(Exception::class);
1762-
$database->createAttribute('datetime_fail', 'date_fail', Database::VAR_DATETIME, 0, false);
1761+
$database->createAttribute('datetime_auto', 'date_auto', Database::VAR_DATETIME, 0, false, filters:['json']);
1762+
$collection = $database->getCollection('datetime_auto_filter');
1763+
$attribute = $collection->getAttributes()[0];
1764+
$this->assertEquals([Database::VAR_DATETIME,'json'], $attribute['filters']);
1765+
$database->updateAttribute('datetime_auto', 'date_auto', Database::VAR_DATETIME, 0, false, filters:[]);
1766+
$collection = $database->getCollection('datetime_auto_filter');
1767+
$attribute = $collection->getAttributes()[0];
1768+
$this->assertEquals([Database::VAR_DATETIME,'json'], $attribute['filters']);
1769+
$database->deleteCollection('datetime_auto_filter');
17631770
}
17641771
/**
17651772
* @depends testCreateDeleteAttribute

tests/e2e/Adapter/Scopes/ObjectAttributeTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public function testObjectAttributeGinIndex(): void
652652
} catch (\Exception $e) {
653653
$exceptionThrown = true;
654654
$this->assertInstanceOf(IndexException::class, $e);
655-
$this->assertStringContainsString('Object indexes do not support explicit orders', $e->getMessage());
655+
$this->assertStringContainsString('Object index do not support explicit orders', $e->getMessage());
656656
}
657657
$this->assertTrue($exceptionThrown, 'Expected Index exception for Object index with orders');
658658

tests/e2e/Adapter/Scopes/VectorTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,7 @@ public function testVectorQuerySum(): void
27112711
$database->deleteCollection('vectorSum');
27122712
}
27132713

2714-
public function testVetorUpsert(): void
2714+
public function testVectorUpsert(): void
27152715
{
27162716
/** @var Database $database */
27172717
$database = static::getDatabase();

tests/unit/Validator/IndexTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function testEmptyAttributes(): void
241241
/**
242242
* @throws Exception
243243
*/
244-
public function testGinIndexValidation(): void
244+
public function testObjectIndexValidation(): void
245245
{
246246
$collection = new Document([
247247
'$id' => ID::custom('test'),

0 commit comments

Comments
 (0)