Repository navigation
fix(migrations): complete 2.6 upgrades and preserve new fields - #14737
Conversation
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (2) — 🟢 2 low
The change threads a
Reviewed commit: e07ecb8 |
🟢 Tier S · Ready to merge
The migration package now targets Appwrite SDK 32 and carries 2.6 descriptions and bucket metadata-stripping settings through resource serialization, source reads, and SDK/direct-database destinations. V25 creates the new video collections before migrating their documents, and the migration tests cover upgrade and transfer behavior. The latest updates also normalize direct-database Documents in the source reader and improve migration failure diagnostics in the E2E helper. Latest changes: The new commits convert direct-database Documents for databases, tables, and indexes to arrays before source serialization, fixing description preservation on that path, and include the migration response message in E2E assertion failures.
📂 Walkthrough · 6
✅ Fixed since the last review · 1
Reviewed the commits since |
There was a problem hiding this comment.
This PR adds description (and a stripMetadata bucket flag) round-tripping through the migration package — source export, resource serialization, destination import — bumps the appwrite SDK to ^32, and extends the V25 migration and e2e tests accordingly.
Key findings
- 🟡
is_arrayguard silently drops descriptions on database source — Appwrite.php:1245 - 🟡 Unguarded SDK model
description/stripMetadatareads abort migration — Appwrite.php:1639
| $newDatabase = self::getDatabase($databaseFamilyType, [ | ||
| 'id' => $database['$id'], | ||
| 'name' => $database['name'], | ||
| 'description' => \is_array($database) && \is_string($database['description'] ?? null) ? $database['description'] : '', |
There was a problem hiding this comment.
🟡 bug · medium
is_array guard silently drops descriptions on database source
The new description guards require \is_array($database), but when the source is SOURCE_DATABASE the reader returns Utopia Document objects (packages/migration/src/Sources/Appwrite/Reader/Database.php:173), which support ArrayAccess but are not arrays. The is_array check therefore always fails and the description is silently reset to '' for every database, table, index and column migrated from a database source (packages/migration/src/Sources/Appwrite.php:1245). The same wrong guard appears in exportEntities, exportIndexes and getColumn.
📋 Prompt for AI Agents
In packages/migration/src/Sources/Appwrite.php at line 1245 (exportDatabases), line 1311 (exportEntities), line 1436 (exportIndexes) and line 3669 (getColumn), change the description guard from \is_array($x) && \is_string($x['description'] ?? null) ? $x['description'] : '' to just \is_string($x['description'] ?? null) ? $x['description'] : ''. The source values are either plain arrays (API reader) or Utopia Database Document objects (database reader), and Document supports ArrayAccess, so the is_array() clause wrongly excludes Documents and silently drops descriptions in SOURCE_DATABASE migrations.
There was a problem hiding this comment.
Fixed in 2bf244a. Database, table, and index exports now normalize Utopia Documents with getArrayCopy() before the array guards; getColumn() already normalizes Documents. The transfer E2E tests initially reproduced lost descriptions, then passed with this fix: 8 tests / 354 assertions for the direct-database source, and again for the remote API source, checking destination metadata through public APIs.
| stripMetadata: $bucket->stripMetadata, | ||
| ))->setDescription($bucket->description); |
There was a problem hiding this comment.
🟡 bug · medium
Unguarded SDK model description/stripMetadata reads abort migration
The new export paths read description and stripMetadata straight off SDK model objects with no null guard, e.g. setDescription($bucket->description) and stripMetadata: $bucket->stripMetadata (packages/migration/src/Sources/Appwrite.php:1639). The Bucket constructor declares a non-nullable bool $stripMetadata and Resource::setDescription() declares a strict string (packages/migration/src/Resource.php:350), so when the source server predates these fields the migration aborts with a TypeError mid-export. The PR itself guards the hazard everywhere else — every array path uses \is_string(... ?? null) and the adjacent bucket line still uses $bucket->transformations ?? false — leaving these live-model reads the only unguarded path into the same fields.
📋 Prompt for AI Agents
In packages/migration/src/Sources/Appwrite.php, harden every unguarded description/stripMetadata read so cross-version migration from servers that predate these fields does not fatal: at lines 1639-1640 change to stripMetadata: $bucket->stripMetadata ?? false and ->setDescription(\is_string($bucket->description ?? null) ? $bucket->description : ''); apply the same \is_string($x->description ?? null) ? $x->description : '' pattern at lines 2251, 2302, 2366, 2378, 2789, 2957, 2969 and 3387 (the $variable, $webhook, $function, $var, $topic, $site, $var and $key model reads). Resource::setDescription() requires a strict string, so a null from an older source server currently raises a TypeError and aborts the whole migration run.
There was a problem hiding this comment.
This does not reproduce with the pinned SDK 32.0.0. Its Models::from() factories initialize fields missing from older server responses before constructing typed models: description defaults to an empty string, and Bucket::from() defaults stripMetadata to false. I verified responses omitting these fields against all seven affected factories: Bucket, FunctionModel, Site, Variable, Topic, Key, and Webhook. The migration receives initialized model properties, so these reads do not introduce the reported TypeError for older servers. No additional SDK release or fallback guards are needed for this case.
There was a problem hiding this comment.
The user's claim is that SDK 32.0.0's Models::from() factories initialize missing fields before constructing typed models, so description defaults to '' and stripMetadata defaults to false. This is a reasonable defense-in-depth argument, but the finding is about the source code in this PR — not about SDK behavior. Let me check the diff more carefully.
Looking at the current diff for packages/migration/src/Sources/Appwrite.php, the bucket path still shows:
stripMetadata: $bucket->stripMetadata(no?? false)->setDescription($bucket->description)(no null guard)
And for all other SDK model reads ($variable->description, $webhook->description, $function->description, $var->description, $topic->description, $site->description, $key->description), the diff shows these are passed directly without guards.
The claim relies entirely on SDK-level initialization guarantees. While SDK 32.0.0 may initialize these fields, the code in this PR does not enforce that behavior at the migration layer. If the SDK is ever updated, downgraded, or used against a truly unexpected server version outside the tested matrix, the TypeError risk remains. The PR's own pattern for array paths (\is_string($x['description'] ?? null) ? $x['description'] : '') is the correct defensive approach, and the live-model paths are inconsistent with it.
The fix has not been applied in the diff — the guards recommended in the original finding are absent.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Problem
The 2.6.0 release gates found two upgrade/transfer gaps after #14730 merged:
stripMetadata, so project transfers lose those settings.Changes
Create the new video collections before migrating their documents, with the existing idempotent collection helper. Update the PHP SDK to 32.0.0 and carry descriptions and metadata stripping through resource serialization, the Appwrite source, and SDK/direct-database destinations. Include descriptions in schema overwrite comparisons and preserve the source side separately from inverse relationship metadata. Carry the SDK's new direct email recipient parameter from existing message data.
Extend the existing migration E2E cases to verify destination descriptions and bucket metadata settings through public APIs. Update memory schemas to the actual 2.6 metadata schema. Seventeen existing PHPStan baseline patterns follow the extended array type spelling; no baseline entries or counts were added.
Validation
Collection not foundbefore the production fix; full V25 unit file passes after it (8 tests, 39 assertions), including a persisted video record across two migration runs.Required for 2.6.0; publish only after this fix is merged and the final release SHA is validated.
Related: appwrite-labs/cloud#6671
Final production candidate
2bf244aalso passes fresh and seeded-upgrade API reads/writes, both gateway HTTP200 checks, self-hosted Console sign-in rendering, two migration runs, and cURL/Swoole rejection of both compromised certificate chains. SDK32 model hydration was checked withdescriptionandstripMetadatamissing: all seven source model types initialize these new fields to the compatible empty/false defaults, so older API responses do not leave these typed properties uninitialized. The review finding about direct database Documents is fixed in2bf244a; both source paths pass their API transfer tests.