diff --git a/app/init/resources.php b/app/init/resources.php index 7731a5c909..fd5d7472e1 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -924,7 +924,7 @@ Http::setResource('getDatabasesDB', function (Group $pools, Cache $cache, Docume $database->getAdapter()->setSupportForAttributes($databaseType !== DOCUMENTSDB); // For separate pools (documentsdb/vectorsdb), check their own shared tables config. - // If not configured, fall back to project's shared tables mode. + // If not configured, use dedicated mode to avoid cross-engine tenant type mismatches. if ($databaseHost !== $dsn->getHost()) { $dbTypeSharedTables = match ($databaseType) { DOCUMENTSDB => \array_filter(\explode(',', System::getEnv('_APP_DATABASE_DOCUMENTSDB_SHARED_TABLES', ''))), @@ -937,23 +937,12 @@ Http::setResource('getDatabasesDB', function (Group $pools, Cache $cache, Docume ->setSharedTables(true) ->setTenant($project->getSequence()) ->setNamespace($dsn->getParam('namespace')); - } elseif (\in_array($dsn->getHost(), $sharedTables)) { - // No dedicated config — inherit project's shared tables mode - $database - ->setSharedTables(true) - ->setTenant($project->getSequence()) - ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) ->setNamespace('_' . $project->getSequence()); } - - try { - $database->create(); - } catch (\Utopia\Database\Exception\Duplicate) { - } } elseif (\in_array($dsn->getHost(), $sharedTables)) { $database ->setSharedTables(true) diff --git a/app/worker.php b/app/worker.php index 6168420a9b..d0fec53972 100644 --- a/app/worker.php +++ b/app/worker.php @@ -259,7 +259,7 @@ Server::setResource('getDatabasesDB', function (Cache $cache, Registry $register $sharedTables = \array_filter(\explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES', ''))); // For separate pools (documentsdb/vectorsdb), check their own shared tables config. - // If not configured, fall back to project's shared tables mode. + // If not configured, use dedicated mode to avoid cross-engine tenant type mismatches. if ($databaseHost !== $dsn->getHost()) { $dbTypeSharedTables = match ($databaseType) { DOCUMENTSDB => \array_filter(\explode(',', System::getEnv('_APP_DATABASE_DOCUMENTSDB_SHARED_TABLES', ''))), @@ -272,23 +272,12 @@ Server::setResource('getDatabasesDB', function (Cache $cache, Registry $register ->setSharedTables(true) ->setTenant($projectDocument->getSequence()) ->setNamespace($dsn->getParam('namespace')); - } elseif (\in_array($dsn->getHost(), $sharedTables, true)) { - // No dedicated config — inherit project's shared tables mode - $database - ->setSharedTables(true) - ->setTenant($projectDocument->getSequence()) - ->setNamespace($dsn->getParam('namespace')); } else { $database ->setSharedTables(false) ->setTenant(null) ->setNamespace('_' . $projectDocument->getSequence()); } - - try { - $database->create(); - } catch (\Utopia\Database\Exception\Duplicate) { - } } elseif (\in_array($dsn->getHost(), $sharedTables, true)) { $database ->setSharedTables(true) diff --git a/tests/e2e/Services/Databases/DocumentsDBConsoleClientTest.php b/tests/e2e/Services/Databases/DocumentsDBConsoleClientTest.php index dedce941f3..7a8e29b9c6 100644 --- a/tests/e2e/Services/Databases/DocumentsDBConsoleClientTest.php +++ b/tests/e2e/Services/Databases/DocumentsDBConsoleClientTest.php @@ -12,11 +12,11 @@ class DocumentsDBConsoleClientTest extends Scope use DatabasesBase; use ProjectCustom; use SideConsole; + use ApiDocumentsDB; protected function setUp(): void { parent::setUp(); $this->requireAdapter('mongodb'); } - use ApiDocumentsDB; } diff --git a/tests/e2e/Services/Databases/DocumentsDBCustomClientTest.php b/tests/e2e/Services/Databases/DocumentsDBCustomClientTest.php index 7bd57b14d6..94b4bc4011 100644 --- a/tests/e2e/Services/Databases/DocumentsDBCustomClientTest.php +++ b/tests/e2e/Services/Databases/DocumentsDBCustomClientTest.php @@ -12,11 +12,11 @@ class DocumentsDBCustomClientTest extends Scope use DatabasesBase; use ProjectCustom; use SideClient; + use ApiDocumentsDB; protected function setUp(): void { parent::setUp(); $this->requireAdapter('mongodb'); } - use ApiDocumentsDB; } diff --git a/tests/e2e/Services/Databases/DocumentsDBCustomServerTest.php b/tests/e2e/Services/Databases/DocumentsDBCustomServerTest.php index 4c53318526..016bc8925c 100644 --- a/tests/e2e/Services/Databases/DocumentsDBCustomServerTest.php +++ b/tests/e2e/Services/Databases/DocumentsDBCustomServerTest.php @@ -12,11 +12,11 @@ class DocumentsDBCustomServerTest extends Scope use DatabasesBase; use ProjectCustom; use SideServer; + use ApiDocumentsDB; protected function setUp(): void { parent::setUp(); $this->requireAdapter('mongodb'); } - use ApiDocumentsDB; } diff --git a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsGuestTest.php b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsGuestTest.php index 3ed2519204..acf63b13f0 100644 --- a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsGuestTest.php +++ b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsGuestTest.php @@ -16,13 +16,13 @@ class DatabasesPermissionsGuestTest extends Scope { use ProjectCustom; use SideClient; + use DatabasesPermissionsScope; protected function setUp(): void { parent::setUp(); $this->requireAdapter('postgresql'); } - use DatabasesPermissionsScope; private $authorization; diff --git a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsMemberTest.php b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsMemberTest.php index babc12343d..7be97f37d3 100644 --- a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsMemberTest.php +++ b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsMemberTest.php @@ -16,13 +16,13 @@ class DatabasesPermissionsMemberTest extends Scope { use ProjectCustom; use SideClient; + use DatabasesPermissionsScope; protected function setUp(): void { parent::setUp(); $this->requireAdapter('postgresql'); } - use DatabasesPermissionsScope; public array $collections = []; diff --git a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsTeamTest.php b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsTeamTest.php index bf3ad8828c..606db172c4 100644 --- a/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsTeamTest.php +++ b/tests/e2e/Services/Databases/VectorsDB/Permissions/DatabasesPermissionsTeamTest.php @@ -16,13 +16,13 @@ class DatabasesPermissionsTeamTest extends Scope { use ProjectCustom; use SideClient; + use DatabasesPermissionsScope; protected function setUp(): void { parent::setUp(); $this->requireAdapter('postgresql'); } - use DatabasesPermissionsScope; public array $collections = []; public string $databaseId = 'testpermissiondb'; diff --git a/tests/e2e/Services/Migrations/MigrationsBase.php b/tests/e2e/Services/Migrations/MigrationsBase.php index 8dc893adc5..662543949a 100644 --- a/tests/e2e/Services/Migrations/MigrationsBase.php +++ b/tests/e2e/Services/Migrations/MigrationsBase.php @@ -4217,9 +4217,10 @@ trait MigrationsBase }, 30_000, 500); // Check that email was sent with download link - $lastEmail = $this->getLastEmail(); + $lastEmail = $this->getLastEmail(probe: function ($email) { + $this->assertEquals('Your JSON export is ready', $email['subject']); + }); $this->assertNotEmpty($lastEmail); - $this->assertEquals('Your JSON export is ready', $lastEmail['subject']); $this->assertStringContainsStringIgnoringCase('Your data export has been completed successfully', $lastEmail['text']); // Extract download URL from email HTML diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index 03723bf231..ebf3486582 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -4598,6 +4598,8 @@ class RealtimeCustomClientTest extends Scope } public function testChannelDocumentsdb() { + $this->requireAdapter('mongodb'); + $user = $this->getUser(); $session = $user['session'] ?? ''; $projectId = $this->getProject()['$id']; @@ -5076,6 +5078,8 @@ class RealtimeCustomClientTest extends Scope public function testChannelVectorsDB() { + $this->requireAdapter('postgresql'); + $user = $this->getUser(); $session = $user['session'] ?? ''; $projectId = $this->getProject()['$id'];