Skip to content

Add Email Templates migration#190

Open
premtsd-code wants to merge 4 commits into
add-custom-domains-migrationfrom
add-email-templates-migration
Open

Add Email Templates migration#190
premtsd-code wants to merge 4 commits into
add-custom-domains-migrationfrom
add-email-templates-migration

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

Summary

  • Adds TYPE_PROJECT_EMAIL_TEMPLATE to GROUP_PROJECTS_RESOURCES for migrating the project's per-locale email template overrides.
  • Source (Sources/Appwrite) reads templates via Project::listEmailTemplates (offset-paginated; not cursor) and emits one EmailTemplate resource per (type, locale).
  • Destination (Destinations/Appwrite) replays them via Project::updateEmailTemplate for each entry.
  • No new group: per the abnegate review on feat(migration): add project-level resource migrations #186, project's own email copy is just another per-project singleton — it belongs in GROUP_PROJECTS alongside PROJECT_VARIABLE / PROJECT_PROTOCOLS / PROJECT_LABELS / PROJECT_SERVICES.

Test plan

  • CI lints + tests green
  • E2E testAppwriteMigrationEmailTemplates (in appwrite/appwrite) passes

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

Adds TYPE_PROJECT_EMAIL_TEMPLATE to the GROUP_PROJECTS migration group so per-locale custom email templates are carried over during an Appwrite-to-Appwrite migration. The source side uses offset pagination against listEmailTemplates; the destination bypasses the SDK's SMTP guard via a direct read-then-merge write to the projects collection.

  • EmailTemplate is a new resource class with a clean serialisation round-trip (body internally, message on the wire) and a getGroup() returning Transfer::GROUP_PROJECTS.
  • exportEmailTemplates in Sources/Appwrite.php paginates with limit/offset and correctly terminates when a partial page is returned, but passes optional SDK response fields (senderName, senderEmail, replyToEmail, replyToName) directly to the string-typed constructor without null coalescing — unlike the matching defensive pattern in EmailTemplate::fromArray — which can throw a TypeError if the Appwrite API returns null for unset sender/reply-to values.
  • createEmailTemplate in Destinations/Appwrite.php follows the same read-then-merge pattern as createServices and createProtocols, with purgeCachedDocument called after each write to keep sequential updates consistent.

Confidence Score: 3/5

The destination write path and the new resource class are solid, but the source export passes optional API fields directly to typed constructor parameters without null-coalescing, which can crash mid-migration for any project whose templates have no custom sender or reply-to values.

The null-coalescing gap in exportEmailTemplates means any template without a custom senderName, senderEmail, replyToEmail, or replyToName (i.e., one using Appwrite defaults) could cause a TypeError that aborts the migration for that project. The same defensive pattern is already applied in EmailTemplate::fromArray, so the fix is straightforward, but the bug is on the hot path of the export loop.

src/Migration/Sources/Appwrite.php — the exportEmailTemplates method around the new EmailTemplate(...) constructor call.

Important Files Changed

Filename Overview
src/Migration/Resources/Templates/EmailTemplate.php New resource class for email templates; clean implementation with correct serialisation round-trip (internal body ↔ API message). fromArray accesses id, templateId, and locale without null guards, which is consistent with other resource classes but relies on callers always supplying those keys.
src/Migration/Sources/Appwrite.php Adds offset-paginated export for email templates. Optional SDK fields (senderName, senderEmail, replyToEmail, replyToName) are passed directly to the EmailTemplate constructor without null coalescing, unlike the defensive pattern used in fromArray, risking a TypeError if the SDK returns null.
src/Migration/Destinations/Appwrite.php Adds createEmailTemplate via direct DB write with read-then-merge; pattern is consistent with createServices and createProtocols. Cache is purged after each write, ensuring sequential per-template writes read fresh data.
src/Migration/Resource.php Adds TYPE_PROJECT_EMAIL_TEMPLATE constant and registers it in the GROUP_PROJECTS_RESOURCES list; straightforward additive change.
src/Migration/Transfer.php Adds TYPE_PROJECT_EMAIL_TEMPLATE to both GROUP_PROJECTS_RESOURCES and the all-resources list; consistent with surrounding entries.

Reviews (1): Last reviewed commit: "Fold email templates into projects group..." | Re-trigger Greptile

Comment thread src/Migration/Sources/Appwrite.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant