From a9e4f07fa2a2f36b4ed69adb7dd4e590acc05d60 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 7 Oct 2025 10:45:47 +0530 Subject: [PATCH 1/2] changed getSupportForAttributes to false in mongodb for documentsdb schemaless support --- src/Database/Adapter/Mongo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Adapter/Mongo.php b/src/Database/Adapter/Mongo.php index 4a80ff751..7b4a06198 100644 --- a/src/Database/Adapter/Mongo.php +++ b/src/Database/Adapter/Mongo.php @@ -2585,7 +2585,7 @@ public function setUTCDatetime(string $value): mixed */ public function getSupportForAttributes(): bool { - return true; + return false; } /** From ff4c8af190e27157649cce500e770811dca8553d Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 13 Oct 2025 12:43:57 +0530 Subject: [PATCH 2/2] added mongodb suite for schemaless --- .github/workflows/tests.yml | 1 + src/Database/Adapter.php | 8 ++ src/Database/Adapter/Mongo.php | 9 +- src/Database/Adapter/Pool.php | 5 + src/Database/Adapter/SQL.php | 5 + tests/e2e/Adapter/MongoDBTest.php | 1 + tests/e2e/Adapter/Schemaless/MongoDBTest.php | 110 +++++++++++++++++++ tests/e2e/Adapter/Scopes/IndexTests.php | 6 +- 8 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 tests/e2e/Adapter/Schemaless/MongoDBTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 025894dd5..0c07f2a42 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,6 +84,7 @@ jobs: SharedTables/MySQL, SharedTables/Postgres, SharedTables/SQLite, + Schemaless/MongoDB, ] steps: diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index d42d86c35..2103a877e 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -1383,4 +1383,12 @@ abstract public function getSupportForUTCCasting(): bool; */ abstract public function setUTCDatetime(string $value): mixed; + /** + * Set support for attributes + * + * @param bool $support + * @return bool + */ + abstract public function setSupportForAttributes(bool $support): bool; + } diff --git a/src/Database/Adapter/Mongo.php b/src/Database/Adapter/Mongo.php index e01ae664d..698cb237e 100644 --- a/src/Database/Adapter/Mongo.php +++ b/src/Database/Adapter/Mongo.php @@ -57,6 +57,7 @@ class Mongo extends Adapter */ private ?array $session = null; // Store session array from startSession protected int $inTransaction = 0; + protected bool $supportForAttributes = true; /** * Constructor. @@ -2585,7 +2586,13 @@ public function setUTCDatetime(string $value): mixed */ public function getSupportForAttributes(): bool { - return false; + return $this->supportForAttributes; + } + + public function setSupportForAttributes(bool $support): bool + { + $this->supportForAttributes = $support; + return $this->supportForAttributes; } /** diff --git a/src/Database/Adapter/Pool.php b/src/Database/Adapter/Pool.php index b7fe28a5f..3b5bb65bd 100644 --- a/src/Database/Adapter/Pool.php +++ b/src/Database/Adapter/Pool.php @@ -599,4 +599,9 @@ public function setUTCDatetime(string $value): mixed { return $this->delegate(__FUNCTION__, \func_get_args()); } + + public function setSupportForAttributes(bool $support): bool + { + return $this->delegate(__FUNCTION__, \func_get_args()); + } } diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index d60af5ff2..c4203b4ad 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -2930,4 +2930,9 @@ public function decodePolygon(string $wkb): array return $rings; } + + public function setSupportForAttributes(bool $support): bool + { + return true; + } } diff --git a/tests/e2e/Adapter/MongoDBTest.php b/tests/e2e/Adapter/MongoDBTest.php index 55b21f8e4..c37b41afe 100644 --- a/tests/e2e/Adapter/MongoDBTest.php +++ b/tests/e2e/Adapter/MongoDBTest.php @@ -51,6 +51,7 @@ public static function getDatabase(): Database ); $database = new Database(new Mongo($client), $cache); + $database->getAdapter()->setSupportForAttributes(true); $database ->setDatabase($schema) ->setNamespace(static::$namespace = 'myapp_' . uniqid()); diff --git a/tests/e2e/Adapter/Schemaless/MongoDBTest.php b/tests/e2e/Adapter/Schemaless/MongoDBTest.php new file mode 100644 index 000000000..e81a42988 --- /dev/null +++ b/tests/e2e/Adapter/Schemaless/MongoDBTest.php @@ -0,0 +1,110 @@ +connect('redis', 6379); + $redis->flushAll(); + $cache = new Cache(new RedisAdapter($redis)); + + $schema = 'utopiaTests'; // same as $this->testDatabase + $client = new Client( + $schema, + 'mongo', + 27017, + 'root', + 'password', + false + ); + + $database = new Database(new Mongo($client), $cache); + $database->getAdapter()->setSupportForAttributes(false); + $database + ->setDatabase($schema) + ->setNamespace(static::$namespace = 'myapp_' . uniqid()); + + if ($database->exists()) { + $database->delete(); + } + + + $database->create(); + + return self::$database = $database; + } + + /** + * @throws Exception + */ + public function testCreateExistsDelete(): void + { + // Mongo creates databases on the fly, so exists would always pass. So we override this test to remove the exists check. + $this->assertNotNull(static::getDatabase()->create()); + $this->assertEquals(true, static::getDatabase()->delete($this->testDatabase)); + $this->assertEquals(true, static::getDatabase()->create()); + $this->assertEquals(static::getDatabase(), static::getDatabase()->setDatabase($this->testDatabase)); + } + + public function testRenameAttribute(): void + { + $this->assertTrue(true); + } + + public function testRenameAttributeExisting(): void + { + $this->assertTrue(true); + } + + public function testUpdateAttributeStructure(): void + { + $this->assertTrue(true); + } + + public function testKeywords(): void + { + $this->assertTrue(true); + } + + protected static function deleteColumn(string $collection, string $column): bool + { + return true; + } + + protected static function deleteIndex(string $collection, string $index): bool + { + return true; + } +} diff --git a/tests/e2e/Adapter/Scopes/IndexTests.php b/tests/e2e/Adapter/Scopes/IndexTests.php index e3fefbd6b..a3bcee5f5 100644 --- a/tests/e2e/Adapter/Scopes/IndexTests.php +++ b/tests/e2e/Adapter/Scopes/IndexTests.php @@ -269,10 +269,10 @@ public function testIndexValidation(): void $this->assertFalse($validator->isValid($newIndex)); - if ($database->getAdapter()->getSupportForAttributes()) { - $this->assertEquals('Attribute "integer" cannot be part of a fulltext index, must be of type string', $validator->getDescription()); - } elseif (!$database->getAdapter()->getSupportForMultipleFulltextIndexes()) { + if (!$database->getAdapter()->getSupportForMultipleFulltextIndexes()) { $this->assertEquals('There is already a fulltext index in the collection', $validator->getDescription()); + } elseif ($database->getAdapter()->getSupportForAttributes()) { + $this->assertEquals('Attribute "integer" cannot be part of a fulltext index, must be of type string', $validator->getDescription()); } try {