Repository navigation
Conversation
…s (HS-1472155) A meta document and its schema counterpart are two separate, non-atomic writes, so a destination can hold a meta document the schema no longer backs — from a run killed between the two writes, or from a project wedged by the stuck-index bug fixed upstream in appwrite/appwrite#15471, where the `indexes` document outlived its schema index. An Overwrite migration drops the schema copy before recreating it. `Utopia\Database`'s `deleteIndex()`/`deleteAttribute()` throw `NotFound` when the key is absent from the collection metadata, and that aborted the import *before* the meta delete that would have let the recreate through — so every retry took the same path and the orphan could never be reconciled through migration at all. Both drop-before-recreate paths now treat "the schema no longer holds it" as the end state the drop asked for, mirroring the upstream fix. The guard narrows to `NotFound`, so a dependent index or a relationship dropped as a column still surfaces as an error. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Code review
Adds NotFound-tolerant schema drops to overwrite recreation for indexes and attributes, with in-memory regression tests for orphaned schema entries. It also adds the PHPStan baseline entries associated with the new test class. Note Not approving while a bug finding is open: Matching orphan metadata still skips schema recreation Findings (1)
Fix with agent prompt### Issue 1
src/Destinations/Appwrite.php:1493
**Matching orphan metadata still skips schema recreation**
If a run stops after writing the metadata document but before creating the schema object, a retry with the same source spec takes the `indexSpecMatches`/`attributeSpecMatches` skip path before reaching this drop. The metadata then appears healthy, so the retry reports a skip while the schema object remains absent; the orphan cleanup sweep also leaves it alone because the source still emits that key. Consider checking schema presence before treating a matching metadata spec as a skip.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Walkthrough (3)
Reviewed Tip Comment |
|
Thanks for contributing! This repository is a read-only mirror; development for this library happens in |
|
|
||
| if ($action === SchemaAction::Overwrite) { | ||
| $dbForDatabases->deleteIndex($this->tableCollectionId($database, $table), $resource->getKey()); | ||
| $this->dropFromSchema(fn () => $dbForDatabases->deleteIndex($this->tableCollectionId($database, $table), $resource->getKey())); |
There was a problem hiding this comment.
Matching orphan metadata still skips schema recreation
If a run stops after writing the metadata document but before creating the schema object, a retry with the same source spec takes the indexSpecMatches/attributeSpecMatches skip path before reaching this drop. The metadata then appears healthy, so the retry reports a skip while the schema object remains absent; the orphan cleanup sweep also leaves it alone because the source still emits that key. Consider checking schema presence before treating a matching metadata spec as a skip.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Destinations/Appwrite.php
Line: 1493
Comment:
**Matching orphan metadata still skips schema recreation**
If a run stops after writing the metadata document but before creating the schema object, a retry with the same source spec takes the `indexSpecMatches`/`attributeSpecMatches` skip path before reaching this drop. The metadata then appears healthy, so the retry reports a skip while the schema object remains absent; the orphan cleanup sweep also leaves it alone because the source still emits that key. Consider checking schema presence before treating a matching metadata spec as a skip.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
|
Re-raised against the monorepo as appwrite/appwrite#15905, per the mirror redirect. Same three-file change. |

Dependency cascade from appwrite/appwrite#15471
No manifest bump is needed
The
appwrite/appwriteComposer constraint here resolves toappwrite/sdk-for-php, not the server monorepo. Upstream #15471 changed onlysrc/Appwrite/Platform/Modules/Databases/Workers/Databases.phpand the server e2e suite — no SDK surface, so no Packagist release followed it. The latest SDK is32.4.0(2026-11-16, before that PR merged on 2026-11-19) and the existing^32.3.0constraint already resolves to it.composer.jsonis therefore unchanged.What does need adapting
src/Destinations/Appwrite.phpdoes not go through the SDK for schema writes — it reimplements the server worker's logic directly againstutopia-php/database. So the upstream root cause has a real counterpart here.A meta document and its schema counterpart are two separate, non-atomic writes, so a destination can hold a meta document the schema no longer backs:
createDocument(META_INDEXES)and$dbForDatabases->createIndex()(the existingcatchcovers thrown errors, not process death), orDELETE .../indexes/{key}answered 204, the worker setstatus=stuck, and theindexesdocument was never removed.An
Overwritemigration drops the schema copy before recreating it.Utopia\Database'sdeleteIndex()/deleteAttribute()throwNotFoundwhen the key is absent from the collection metadata (verified in the resolvedutopia-php/database8.3.15), and that aborted the import before the meta delete that would have let the recreate through. Every retry took the same path, so the orphan could not be reconciled through migration at all — the same wedge as the ticket, on the destination side.Note the asymmetry this closes: the orphan cleanup sweep already wrapped
deleteIndexinbestEffort, but that sweep only visits destination keys absent from the source. An orphan whose key the source still emits falls to theOverwritepath, which was unguarded.Changes
dropFromSchema()helper: treats "the schema no longer holds it" as the end state the drop asked for. Unlike the neighbouringbestEffort()it narrows toNotFound, so a dependent index (Dependency) or a relationship dropped as a column still surfaces as an error.createIndex()'sSchemaAction::Overwritebranch (the direct mirror of the upstream fix) anddropAttributeForRecreate(). Upstream only had to fix the index path because the server's attribute path already caughtNotFound; here both were unguarded, and the PR description calls that attribute behaviour the correct reference.The second upstream bug (pruning
lengths/ordersby value witharray_diffinstead of positionally) has no counterpart here — migration never prunes an index's column list; it writes the source spec wholesale.Tests
tests/Destinations/AppwriteOrphanSchemaDropTest.php, two failing-first tests on the existing in-memory harness. Each builds the orphan the honest way — transfer the schema, then drop only the schema copy via the realdeleteIndex()/deleteAttribute(), leaving the meta document — then re-runs asOverwrite:testAnIndexTheSchemaNoLongerHoldsIsRecreated— the re-run changes the orders so the spec cannot match into aSkip. Asserts the import reports no error, the index is back in the schema carrying the new spec (['ASC','DESC']), and the orphan was replaced rather than duplicated.testAColumnTheSchemaNoLongerHoldsIsRecreated— a type change, which has no in-place primitive and so is forced through the drop.Both assert their own orphan precondition so they cannot silently stop testing the branch.
Without the fix they fail with exactly the ticket's symptoms:
Verification
Local PHP is 8.4 and this package's suite runs from the monorepo toolchain, so everything below ran in a
php:8.5-clicontainer with deps installed from this tree:phpunit --testsuite unit→ OK, 227 tests, 1144 assertions, 2 skipped (225 before these two).phpstan analyse(level max) → output identical to cleanHEAD; the 5 remaining errors are pre-existing drift between the committed baseline and the phpstan build used here, untouched by this change.phpstan-baseline.neongains the twoTransfersColumnstrait-context entries that every sibling test class using that trait already has (the baseline keys them per using-class path). The three errors in the new file itself were fixed rather than baselined.rectoris a no-op here —rector.phpskips bothsrcandtests.Heads up on routing
This package's canonical source is now
packages/migrationin the monorepo, and this repo's only workflow redirects PRs toappwrite/appwrite, so the mirror bot will likely redirect this one. Raised here because this is the repository the task targeted; happy to re-raise it against the monorepo instead.🤖 Generated with Claude Code