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 66c34e5d9..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 true; + 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 {