Repository navigation
fix(databases): resolve physical collections through the databases handle - #14130
Conversation
…ndle A dedicated database keeps its physical collections (database_N_collection_M, their _metadata rows and their row cache) on its own compute, reached through getDatabasesDB($database). Several HTTP actions still read or changed those collections through dbForProject, which only holds the platform metadata (databases, database_N, attributes, indexes). In CE both handles point at the same database so nothing showed; on a dedicated database: - relationship create answered 404 for every relationship, because both physical collections were looked up on the project database - every attribute/column update (updateAttribute, updateAttributeDefault, updateRelationship) targeted a collection that does not exist there - nested related rows on document create/update were read from the project database, and a transaction commit loaded its collection schema from it, so relationship permission checks ran against an empty schema - collection-create cleanup dropped the physical collection on the wrong database, and attribute capability/limit checks, the required-spatial row count and the row-cache purges used the project adapter and cache Thread getDatabasesDB into the attribute/column create, update and delete actions (Collections API and TablesDB) and route every physical-collection operation through it, matching Collections/Create, Indexes/Create and the Databases worker. Metadata documents stay on dbForProject. The worker's own row-cache purges move to dbForDatabases for the same reason, and the transaction commit helpers' parameter is renamed to the handle it receives. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔵 Tier A · Mergeable after minor fixes
The PR routes physical collection operations, nested related-document reads, capability checks, and cache invalidation through the databases handle while leaving platform metadata on the project handle. It threads database resolution through attribute actions and TablesDB subclasses, and updates collection cleanup and worker purges. Transaction commits now resolve the actual database document for every database type and reject operations spanning different database DSNs before executing writes. Latest changes: The newest commit replaces project-only transaction resolution with an actual database lookup and checks that all operation databases use the same DSN before committing.
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php:86
**Inject the database factory object rather than a callable**
AGENTS.md's DI and Reuse rules explicitly require object dependencies and forbid injecting callbacks; the newly added `getDatabasesDB` injections extend that prohibited pattern across the attribute actions and TablesDB subclasses. Please inject the factory object and put database resolution on that domain object instead.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 8
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
Reviewed the commits since |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…base Commit resolved the handle for legacy and TablesDB transactions from the project DSN, so on a dedicated database the staged operations were applied to (and their schemas read from) the project database, where those collections do not exist. Resolve the handle from the first operation's database for every type, as DocumentsDB and VectorsDB already did. One withTransaction() can only be atomic on one handle, so a transaction whose operations target databases on different database instances is now refused with transaction_invalid instead of silently writing to the wrong one. Databases sharing the project database (all of CE) still commit together. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #14130 (route physical collection reads, schema checks, cache purges and transaction commits through the databases handle), #14120's merge commit, #14137 (VCS tag globs) and #14139 (project SMTP failures finish the mail job). Conflicts were resolved by keeping the database 8.0 forms the train already uses (ColumnType cases, Capability checks via supports(), Attribute::fromArray for checkAttribute, supportsSpatial/ supportsRelationships helpers) while taking main's databases-handle routing, so dedicated databases get their own adapter's capabilities and schema. The spatial capability check moves after the database lookup because it now needs that database's adapter. Documents Create/Update keep the train's RelationshipValues, which already reads stored related documents through the databases handle; main's inline permission walk is superseded by it. Transactions increment/decrement now build their Counter from the databases handle, since main renamed the handler parameter and the counted collection's schema lives on that handle. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
On a dedicated database, the physical collections (
database_N_collection_M, their_metadatarows and their row cache) live on the database's own compute, reached throughgetDatabasesDB($database). Several HTTP actions inModules/Databasesstill read or changed those collections through$dbForProject, which only holds the platform metadata (databases,database_N,attributes,indexes). In CE both handles resolve to the same database, so nothing is visible there; on cloud dedicated databases:table_not_foundfor every relationship. Both physical collections were looked up with$dbForProject->getCollection(...). Found by the cloud dedicated TablesDB e2e (TablesDBTest::testDeleteColumnOnDedicatedDatabasearea): "Creating the two-way relationship failed: Table with the requested ID ... could not be found".updateAttribute(),updateAttributeDefault()andupdateRelationship()targeted a collection that does not exist on the project database.The fix follows the pattern already used by
Collections/Create,Collections/Update,Indexes/Createand the Databases worker: injectgetDatabasesDB, resolve$dbForDatabases = $getDatabasesDB($database)once the database document is found, and run every physical-collection operation through it. Metadata documents stay on$dbForProject.Sites fixed
Databases/Collections/Attributes/Relationship/Create.phpgetCollectionof the parent and related physical collections;getSupportForRelationships$dbForProject→$dbForDatabases(support check moved after the database lookup)Databases/Collections/Attributes/Action.phpcreateAttribute()getSupportForSpatialIndexNull,count()of the physical collection,checkAttribute()(both sides), 4 physicalpurgeCachedCollection$dbForDatabasesDatabases/Collections/Attributes/Action.phpupdateAttribute()updateRelationship,updateAttribute,updateAttributeDefault$dbForDatabasesDatabases/Collections/Attributes/Delete.php(+ TablesDBColumns/Delete.php)getSupportForCastIndexArray, 2 physical purges$dbForDatabasesDatabases/Collections/Create.phpcleanup()deleteCollection$dbForDatabases(cleanup()takes both handles)Databases/Collections/Documents/Create.phpgetDocument$dbForDatabases(resolved before the permission closure)Databases/Collections/Documents/Update.phpgetDocument$dbForDatabasesDatabases/Transactions/Update.phpgetCollection($collectionId)withTransaction()is only atomic on one handle, so operations spanning databases on different instances are refused withtransaction_invalid; databases sharing the project database (all of CE) commit together as before. Thehandle*Operationhelpers already received$dbForDatabasesbut named the parameter$dbForProject, so it is renamed (rename only).Workers/Databases.phppurgeCachedCollection$dbForDatabases(the handle the worker already uses for the DDL)Plumbing:
getDatabasesDBis injected into all 18 attribute Create and 18 Update actions and into AttributesDelete, plus their TablesDBColumns/*subclasses (inject only, since they reuse the parentaction()). It is passed tocreateAttribute()/updateAttribute(). After the change, a multi-line audit ofModules/Databasesfinds no$dbForProjectcall on adatabase_*_collection_*id.Not changed: the per-type spatial pre-checks in
Point/Line/PolygonCreate/Update and the support check inRelationship/Updatestill read the project adapter before the database is resolved. They are not physical-collection operations.createAttribute()now repeats the spatial check against the dedicated adapter, and an update needs an attribute that already exists.Test Plan
[OK] No errors.php -lon all 80 changed files.getDatabasesDB($database)anddbForProjectresolve to the same database in CE (Factory::tenant()takes the project DSN when the database document has nodatabaseDSN), so the old and new code read the same rows. The existing CE Databases/TablesDB relationship, attribute-update, document and transaction e2e suites must stay green and are the regression guard for CE behaviour.TablesDBTest::testDeleteColumnOnDedicatedDatabase(appwrite-labs/cloud, real-Edge dedicated TablesDB lane) reproduced the relationship-create 404 on two pins (runs 37280286280 / 37281427657). Once cloud re-pins server-ce to a commit with this fix, that test will be extended to create and delete a two-way relationship on the dedicated database. It covers this change end to end.Related PRs and Issues
Checklist
🤖 Generated with Claude Code