Skip to content

feat: add overwrite and skip options to DestinationAppwrite#169

Draft
premtsd-code wants to merge 2 commits intomainfrom
feat/skip-duplicates
Draft

feat: add overwrite and skip options to DestinationAppwrite#169
premtsd-code wants to merge 2 commits intomainfrom
feat/skip-duplicates

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

Summary

Adds two new behavior flags to DestinationAppwrite so CSV / JSON / appwrite→appwrite imports can control how duplicate-id rows are handled:

  • overwrite=true → use upsertDocuments() instead of createDocuments(). Replaces existing rows with imported values.
  • skip=true → wrap createDocuments() in skipDuplicates() scope guard. Silently no-ops duplicate ids at the adapter layer (INSERT IGNORE equivalent); existing rows are preserved unchanged.
  • Both false (default): plain createDocuments(), fails fast on DuplicateException. Original behavior, unchanged.
  • Both true: overwrite wins (upsert subsumes skip).

The existing skipRelationshipsExistCheck() FK-guard wrapper is preserved in all three branches.

Changes

  • src/Migration/Destinations/Appwrite.php — constructor accepts bool $overwrite = false, bool $skip = false; createRecord() row-buffer flush dispatches on the flags
  • composer.json — temporarily pinned utopia-php/database to dev-csv-import-upsert-v2 as 5.99.0 to get the skipDuplicates() scope guard

Blocker

Depends on utopia-php/database#852 — the skipDuplicates() scope guard doesn't exist in any released version of utopia-php/database yet. composer.json is pinned to the PR branch and must be reset to the proper release version (^5.X.Y) once #852 merges and utopia-php/database ships a release.

This PR should stay in draft until then.

Test plan

  • Static analysis (PHPStan level 3) clean on the edited file
  • Pint / PSR-12 format clean
  • E2E coverage exists in appwrite feat/skip-duplicatestestCreateCSVImportSkipDuplicates, testCreateCSVImportOverwrite, testCreateCSVImportDefaultFailsOnDuplicate. All three pass locally against a full appwrite stack.

Downstream PRs

CSV / JSON / appwrite-to-appwrite imports that re-run on the same
batch (e.g. user re-uploads the same file, or a worker retries a
failed chunk) currently throw DuplicateException and abort the whole
batch. Wrap the row-buffer flush in the new skipDuplicates() scope
guard so duplicate-by-id rows are silently no-op'd at the adapter
layer (INSERT IGNORE / ON CONFLICT DO NOTHING / $setOnInsert), letting
the rest of the batch proceed.

The existing skipRelationshipsExistCheck() wrapper is preserved
(FK-target guard); skipDuplicates composes around it.

Feature-branch note: depends on utopia-php/database's skipDuplicates()
scope guard from PR utopia-php/database#852. composer.json is
temporarily pinned to dev-csv-import-upsert-v2 with a 5.99.0 alias so
composer can resolve the 5.* constraint transitively. Must be reset
to the proper release version (^5.X.Y) once PR #852 merges and
utopia-php/database ships.
Per Jake's spec, migration destinations accept two new behavior flags:

- overwrite=true → use upsertDocuments() instead of createDocuments()
  Replaces existing rows with the imported values. Naturally handles
  duplicate ids.

- skip=true → wrap createDocuments() in skipDuplicates() scope guard.
  Silently no-ops duplicate ids at the adapter layer (INSERT IGNORE
  equivalent). Existing rows are preserved.

Default (both false): plain createDocuments, fails fast on
DuplicateException. Original behavior, unchanged for existing callers.

Precedence when both set: overwrite wins (upsert subsumes skip).

The existing skipRelationshipsExistCheck() FK-guard wrapper is
preserved in all three branches.
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