Skip to content

Commit bcd8148

Browse files
* added dynamic changing of support for attributes to toggle schema and schemaless
* updated ci to include tests with both mongodb support for attributes and not support for attributes
1 parent 4240449 commit bcd8148

File tree

7 files changed

+42
-4
lines changed

7 files changed

+42
-4
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ jobs:
8585
SharedTables/Postgres,
8686
SharedTables/SQLite,
8787
]
88+
include:
89+
- adapter: MongoDB
90+
support_for_attributes: false
91+
92+
- adapter: MongoDB
93+
support_for_attributes: true
8894

8995
steps:
9096
- name: checkout
@@ -105,4 +111,7 @@ jobs:
105111
106112
- name: Run Tests
107113
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/e2e/Adapter/${{matrix.adapter}}Test.php --debug
114+
115+
env:
116+
SUPPORT_FOR_ATTRIBUTES: ${{ matrix.support_for_attributes || 'false' }}
108117

src/Database/Adapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,4 +1383,12 @@ abstract public function getSupportForUTCCasting(): bool;
13831383
*/
13841384
abstract public function setUTCDatetime(string $value): mixed;
13851385

1386+
/**
1387+
* Set support for attributes
1388+
*
1389+
* @param bool $support
1390+
* @return bool
1391+
*/
1392+
abstract public function setSupportForAttributes(bool $support): bool;
1393+
13861394
}

src/Database/Adapter/Mongo.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Mongo extends Adapter
5757
*/
5858
private ?array $session = null; // Store session array from startSession
5959
protected int $inTransaction = 0;
60+
protected bool $supportForAttributes = true;
6061

6162
/**
6263
* Constructor.
@@ -2585,7 +2586,13 @@ public function setUTCDatetime(string $value): mixed
25852586
*/
25862587
public function getSupportForAttributes(): bool
25872588
{
2588-
return false;
2589+
return $this->supportForAttributes;
2590+
}
2591+
2592+
public function setSupportForAttributes(bool $support): bool
2593+
{
2594+
$this->supportForAttributes = $support;
2595+
return $this->supportForAttributes;
25892596
}
25902597

25912598
/**

src/Database/Adapter/Pool.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,9 @@ public function setUTCDatetime(string $value): mixed
599599
{
600600
return $this->delegate(__FUNCTION__, \func_get_args());
601601
}
602+
603+
public function setSupportForAttributes(bool $support): bool
604+
{
605+
return $this->delegate(__FUNCTION__, \func_get_args());
606+
}
602607
}

src/Database/Adapter/SQL.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,4 +2930,9 @@ public function decodePolygon(string $wkb): array
29302930

29312931
return $rings;
29322932
}
2933+
2934+
public function setSupportForAttributes(bool $support): bool
2935+
{
2936+
return true;
2937+
}
29332938
}

tests/e2e/Adapter/MongoDBTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public static function getDatabase(): Database
6161

6262
$database->create();
6363

64+
$supportForAttributes = getenv('SUPPORT_FOR_ATTRIBUTES');
65+
$supportForAttributes = filter_var($supportForAttributes, FILTER_VALIDATE_BOOL);
66+
$database->getAdapter()->setSupportForAttributes($supportForAttributes);
67+
6468
return self::$database = $database;
6569
}
6670

tests/e2e/Adapter/Scopes/IndexTests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ public function testIndexValidation(): void
269269

270270
$this->assertFalse($validator->isValid($newIndex));
271271

272-
if ($database->getAdapter()->getSupportForAttributes()) {
273-
$this->assertEquals('Attribute "integer" cannot be part of a fulltext index, must be of type string', $validator->getDescription());
274-
} elseif (!$database->getAdapter()->getSupportForMultipleFulltextIndexes()) {
272+
if (!$database->getAdapter()->getSupportForMultipleFulltextIndexes()) {
275273
$this->assertEquals('There is already a fulltext index in the collection', $validator->getDescription());
274+
} elseif ($database->getAdapter()->getSupportForAttributes()) {
275+
$this->assertEquals('Attribute "integer" cannot be part of a fulltext index, must be of type string', $validator->getDescription());
276276
}
277277

278278
try {

0 commit comments

Comments
 (0)