Skip to content

Support duplicate handling for Appwrite imports#205

Open
premtsd-code wants to merge 7 commits into
mainfrom
skip-override-migration
Open

Support duplicate handling for Appwrite imports#205
premtsd-code wants to merge 7 commits into
mainfrom
skip-override-migration

Conversation

@premtsd-code

@premtsd-code premtsd-code commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add Appwrite duplicate handling modes for skip and overwrite across imported resources
  • carry createdAt and updatedAt through Appwrite source resources so overwrite only updates when the source is newer
  • preserve fail-mode create behavior as the default path
  • overwrite SDK-backed resources in place where supported, match natural-key resources such as memberships/platforms/rules, and replace existing files by deleting only the matching destination file ID before re-upload
  • keep deployment overwrite conservative: existing function/site deployments are skipped instead of deleted and recreated

Validation

  • composer format
  • composer lint
  • composer check
  • live source-to-destination fail-mode migration
  • live skip-mode migration with source-only resources and existing destination conflicts
  • live overwrite-mode migration with matching resources, source-only resources, and destination-only sentinels
  • live file overwrite check confirmed matching file content is replaced, source-only file is created, and unrelated destination file is preserved

Review Notes

  • overwrite only applies when the source updatedAt is newer than destination updatedAt; otherwise the resource is skipped
  • file overwrite deletes only the matching file ID in the matching bucket, then reuses the existing upload path
  • deployment overwrite remains skipped because safely replacing deployment artifacts needs a separate delete-and-reupload recovery path

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds skip and overwrite duplicate-handling modes to the Appwrite-to-Appwrite migration destination, propagates createdAt/updatedAt timestamps through all resource models, and extracts applyUserState/applyTeamState/createSubscriberOnDestination helpers. The new handleDuplicate central dispatcher drives timestamp-based decisions (skip if destination is newer or equal, overwrite if source is newer) across buckets, files, users, teams, memberships, functions, env vars, sites, messaging providers, topics, subscribers, messages, webhooks, platforms, API keys, proxy rules, and project variables.

  • All 13 resource model files gain optional createdAt/updatedAt constructor parameters passed through by the Appwrite source, enabling the timestamp comparison in handleDuplicate::resolveSchemaAction.
  • A skippedChunkedUploads map tracks skip verdicts across multi-chunk file and deployment uploads so later chunks are correctly short-circuited.
  • The deployment overwrite branch (importDeploymentWithDuplicateCheck and importSiteDeploymentWithDuplicateCheck) deletes the existing deployment before re-uploading, which contradicts the PR's stated design of conservatively skipping deployments in overwrite mode.

Confidence Score: 4/5

Safe to merge for skip mode; the overwrite path for function and site deployments deletes before re-uploading, which is riskier than the stated intent and should be confirmed or corrected before enabling overwrite mode in production.

The deployment overwrite branches call deleteDeployment then re-upload, while the PR's own Review Notes describe these as conservatively skipped. If that note reflects the real design decision, the delete is unintended and could leave a deployment permanently absent if the re-upload fails. Everything else — the timestamp gating, the skippedChunkedUploads tracker, and the resource model timestamp additions — looks correct and well-structured.

src/Migration/Destinations/Appwrite.php — specifically importDeploymentWithDuplicateCheck (line 2810) and importSiteDeploymentWithDuplicateCheck (line 3702), where the overwrite branch deletes the existing deployment rather than skipping it.

Important Files Changed

Filename Overview
src/Migration/Destinations/Appwrite.php Core destination handler gains skip/overwrite duplicate handling for all resource types; deployment overwrite behavior contradicts the stated design intent in the PR description
src/Migration/Sources/Appwrite.php Passes createdAt/updatedAt through to all resource models so the destination can drive skip/overwrite timestamp comparisons; straightforward additive change
src/Migration/Resources/Auth/User.php Adds createdAt/updatedAt parameters to constructor and serialization; non-breaking additive change
src/Migration/Resources/Auth/Membership.php Adds createdAt/updatedAt parameters to constructor and serialization; non-breaking additive change
src/Migration/Resources/Functions/Deployment.php Adds createdAt/updatedAt parameters; non-breaking additive change
src/Migration/Resources/Sites/Deployment.php Adds createdAt/updatedAt parameters; non-breaking additive change
src/Migration/Resources/Storage/File.php Adds createdAt/updatedAt parameters; non-breaking additive change

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/Migration/Destinations/Appwrite.php:2810-2812
**Deployment overwrite contradicts stated design**

The PR's Review Notes explicitly say "existing function/site deployments are skipped instead of deleted and recreated," yet this code deletes the deployment and re-uploads it in `OnDuplicate::Overwrite` mode. If the intent was the conservative skip described in the notes, the overwrite branch should set `STATUS_SKIPPED` and return early — mirroring the `OnDuplicate::Skip` branch above — rather than calling `deleteDeployment`. The same mismatch exists in `importSiteDeploymentWithDuplicateCheck` (line 3702).

Reviews (7): Last reviewed commit: "Merge main into skip override migration" | Re-trigger Greptile

Comment thread src/Migration/Destinations/Appwrite.php Outdated
Comment thread src/Migration/Destinations/Appwrite.php
Comment thread src/Migration/Resources/Backups/Policy.php
Comment thread src/Migration/Destinations/Appwrite.php
Comment thread src/Migration/Destinations/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