Repository navigation
fix(migration): repair missing email metadata attributes in V25 - #13820
Conversation
The five email metadata attributes on the users collection -- emailCanonical, emailIsFree, emailIsDisposable, emailIsCorporate and emailIsCanonical -- are created only by V23, inside a try/catch that swallows failure with a warning. V25's users arm creates only passwordPwned, and the migrate task runs a single version class, so an install whose V23 users step failed, or one that upgraded straight from 1.8.x, ends up with a users collection missing all five. Every user write puts those keys in the create payload, so such an install fails all of them with Invalid document structure: Unknown attribute: "emailCanonical". Create the attributes from the collection config in V25's users arm, the same repair already applied to the functions and sites arms for the provider attributes. createAttributesFromCollection() skips ids the collection already has, so this is a no-op on healthy installs.
|
| try { | ||
| $this->createAttributesFromCollection($this->dbForProject, $id, $attributes); | ||
| } catch (Throwable $th) { | ||
| Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$id}: {$th->getMessage()}"); | ||
| } |
There was a problem hiding this comment.
Missing upgrade regression coverage
This schema repair has no behavioral test for the failure it fixes. Existing V25 coverage exercises only the functions and sites repairs, while failures here are reduced to warnings and can leave user writes broken. Add an upgrade test that begins with the affected legacy users schema, runs the migration twice, and verifies through a user create or update operation that writes succeed. Avoid merely asserting that the five configured attribute IDs exist, since that would duplicate implementation details rather than test observable behavior.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Migration/Version/V25.php
Line: 266-270
Comment:
**Missing upgrade regression coverage**
This schema repair has no behavioral test for the failure it fixes. Existing V25 coverage exercises only the functions and sites repairs, while failures here are reduced to warnings and can leave user writes broken. Add an upgrade test that begins with the affected legacy users schema, runs the migration twice, and verifies through a user create or update operation that writes succeed. Avoid merely asserting that the five configured attribute IDs exist, since that would duplicate implementation details rather than test observable behavior.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Starts from a users collection frozen in its pre-V23 shape, runs migrateCollections twice, then writes a user carrying the five email metadata attributes. Without the repair the write fails with Invalid document structure: Unknown attribute: "emailCanonical", which is the failure an affected install actually hits; asserting the attribute ids are present would only restate the migration.
The test built only the two collections the users arm happens to touch and reached migrateCollections by reflection. Build the project database the way provisioning builds it instead -- audit plus every metadata collection from the config, with users frozen in its pre-V23 shape -- so the public execute() entrypoint the migrate task calls can run end to end. One run is enough for the claim in the name; the repeat run that showed the repair was idempotent is already covered by testV25RepairsProviderAttributesIdempotently.
What does this PR do?
The five email metadata attributes on the
userscollection —emailCanonical,emailIsFree,emailIsDisposable,emailIsCorporateandemailIsCanonical— are created only by V23, inside atry/catchthat swallows failure with a warning. V25's users arm creates onlypasswordPwned, and the migrate task runs a single version class, so an install whose V23 users step failed ends up with auserscollection missing all five.Creates and the email-update paths put those keys in the payload, so on such an install they fail with
Invalid document structure: Unknown attribute: "emailCanonical".This creates the attributes from the collection config in V25's users arm — the same repair already applied to the functions and sites arms for the provider attributes.
createAttributesFromCollection()skips ids the collection already has, so it is a no-op on healthy installs.Test Plan
composer lint src/Appwrite/Migration/Version/V25.php→{"tool":"pint","result":"passed"}Migration::createAttributesFromCollectionthat existing attribute ids are filtered out, so re-running is idempotent.Not run: the migration was not executed against a real seeded stack — that needs a 1.8.x install upgraded with volumes retained, which was not available here. Worth exercising on the standard upgrade gate before release.
Related PRs and Issues
Note for the reporter:
Migration::$versionsmaps 1.9.0–1.9.5 to V24, so a target of exactly 1.9.0 does not pick this repair up. Upgrading to 1.9.6 or any 2.x target does.Checklist