Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
SharedTables/MySQL,
SharedTables/Postgres,
SharedTables/SQLite,
Schemaless/MongoDB,
]

steps:
Expand Down
8 changes: 8 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
9 changes: 8 additions & 1 deletion src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Adapter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 5 additions & 0 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2930,4 +2930,9 @@ public function decodePolygon(string $wkb): array

return $rings;
}

public function setSupportForAttributes(bool $support): bool
{
return true;
}
}
1 change: 1 addition & 0 deletions tests/e2e/Adapter/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
110 changes: 110 additions & 0 deletions tests/e2e/Adapter/Schemaless/MongoDBTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Tests\E2E\Adapter;

use Exception;
use Redis;
use Utopia\Cache\Adapter\Redis as RedisAdapter;
use Utopia\Cache\Cache;
use Utopia\Database\Adapter\Mongo;
use Utopia\Database\Database;
use Utopia\Mongo\Client;

class MongoDBTest extends Base
{
public static ?Database $database = null;
protected static string $namespace;

/**
* Return name of adapter
*
* @return string
*/
public static function getAdapterName(): string
{
return "mongodb";
}

/**
* @return Database
* @throws Exception
*/
public static function getDatabase(): Database
{
if (!is_null(self::$database)) {
return self::$database;
}

$redis = new Redis();
$redis->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;
}
}
6 changes: 3 additions & 3 deletions tests/e2e/Adapter/Scopes/IndexTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down