Skip to content

Add webhook migration support#185

Open
premtsd-code wants to merge 3 commits into
add-project-variable-migrationfrom
add-webhook-migration
Open

Add webhook migration support#185
premtsd-code wants to merge 3 commits into
add-project-variable-migrationfrom
add-webhook-migration

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

Summary

Stacks on #184. Adds webhook as a migrable resource.

  • Source: Appwrite SDK Webhooks::list() (separate service from Project) with cursor pagination. Reports via reportIntegrations.
  • Destination: direct dbForPlatform->createDocument('webhooks', ...) matching the upstream Webhooks::Create payload exactly.

Notes

  • Resource::TYPE_WEBHOOK = 'webhook', placed in GROUP_INTEGRATIONS_RESOURCES.
  • Carries through name, url, events, security (TLS), httpUser/httpPass (basic auth), and enabled.
  • Signing secret regenerates: the SDK strips signatureKey on list responses (Webhooks/XList.php explicitly removeAttribute('signatureKey')). Destination generates a fresh bin2hex(random_bytes(64)) to match upstream's createWebhook default. Webhook receivers verifying signatures must be updated with the destination's new key.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR adds webhook as a migratable resource, implementing both the source export (via Appwrite\\Services\\Webhooks::list() with cursor pagination) and destination import (writing directly to dbForPlatform). The implementation mirrors the existing ProjectVariable migration from PR #184.

  • Source (Sources/Appwrite.php): adds exportWebhooks() and webhook counting in reportSettings, using the same total === 0 / count < batchSize pagination pattern as exportProjectVariables.
  • Resource (Resources/Settings/Webhook.php): new resource class carrying name, url, events, security, httpUser/httpPass, and enabled; signatureKey is intentionally omitted.
  • Destination (Destinations/Appwrite.php): createWebhook() writes to dbForPlatform, regenerates signatureKey via bin2hex(random_bytes(64)), and purges the project cache.

Confidence Score: 5/5

Safe to merge; the changes are a well-scoped addition that mirrors the established ProjectVariable migration pattern throughout.

The webhook migration is a faithful extension of the existing ProjectVariable pattern: source pagination, destination deduplication, and dbForPlatform writes are all consistent with the surrounding code. The deliberate signatureKey regeneration is correctly documented and mirrors Appwrite's own createWebhook behavior. No functional regressions are introduced in shared code paths.

No files require special attention.

Important Files Changed

Filename Overview
src/Migration/Resources/Settings/Webhook.php New resource class; clean implementation with typed properties, fromArray, jsonSerialize, and accessors matching the ProjectVariable pattern.
src/Migration/Sources/Appwrite.php Adds exportWebhooks() and webhook reporting to reportSettings; pagination logic mirrors exportProjectVariables exactly.
src/Migration/Destinations/Appwrite.php Adds createWebhook() using dbForPlatform with name-only dedup and fresh signatureKey generation; name-only dedup limitation was already flagged in previous review threads.
src/Migration/Resource.php Adds TYPE_WEBHOOK constant and registers it in the appropriate group.
src/Migration/Transfer.php Adds TYPE_WEBHOOK to GROUP_SETTINGS_RESOURCES and the flat resource list, consistent with the Webhook class and source/destination.

Reviews (4): Last reviewed commit: "Merge remote-tracking branch 'origin/add..." | Re-trigger Greptile

Comment thread src/Migration/Destinations/Appwrite.php Outdated
Comment on lines +3233 to +3236
$existing = $this->dbForPlatform->findOne('webhooks', [
Query::equal('projectInternalId', [$this->projectInternalId]),
Query::equal('name', [$resource->getWebhookName()]),
]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Name-only dedup silently drops duplicate-named webhooks

The idempotency check matches on projectInternalId + name, but Appwrite does not enforce unique webhook names within a project. If the source project has two webhooks sharing the same name (e.g. "My Webhook") pointing to different URLs, the second one is silently skipped with "Webhook already exists" — resulting in undetected data loss. Adding url to the dedup query would distinguish same-named webhooks and avoid the false positive.

@premtsd-code premtsd-code force-pushed the add-project-variable-migration branch from c040472 to 3376bed Compare May 14, 2026 19:00
- Resource::TYPE_WEBHOOK joins project-variable under the Settings group.
- Source uses Appwrite SDK Webhooks::list() (separate service from
  Project) with cursor pagination.
- Destination writes to dbForPlatform.webhooks matching upstream
  createWebhook payload. Signing secret regenerates on the destination
  because the SDK strips it from list responses (same caveat as api keys).
@premtsd-code premtsd-code force-pushed the add-webhook-migration branch from 6bd9699 to 7fca422 Compare May 14, 2026 19:27
…into add-webhook-migration

# Conflicts:
#	src/Migration/Destinations/Appwrite.php
#	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