feat: add overwrite and skip options to DestinationAppwrite#169
Draft
premtsd-code wants to merge 2 commits intomainfrom
Draft
feat: add overwrite and skip options to DestinationAppwrite#169premtsd-code wants to merge 2 commits intomainfrom
premtsd-code wants to merge 2 commits intomainfrom
Conversation
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.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new behavior flags to
DestinationAppwriteso CSV / JSON / appwrite→appwrite imports can control how duplicate-id rows are handled:overwrite=true→ useupsertDocuments()instead ofcreateDocuments(). Replaces existing rows with imported values.skip=true→ wrapcreateDocuments()inskipDuplicates()scope guard. Silently no-ops duplicate ids at the adapter layer (INSERT IGNOREequivalent); existing rows are preserved unchanged.createDocuments(), fails fast onDuplicateException. Original behavior, unchanged.overwritewins (upsert subsumes skip).The existing
skipRelationshipsExistCheck()FK-guard wrapper is preserved in all three branches.Changes
src/Migration/Destinations/Appwrite.php— constructor acceptsbool $overwrite = false, bool $skip = false;createRecord()row-buffer flush dispatches on the flagscomposer.json— temporarily pinnedutopia-php/databasetodev-csv-import-upsert-v2 as 5.99.0to get theskipDuplicates()scope guardBlocker
Depends on utopia-php/database#852 — the
skipDuplicates()scope guard doesn't exist in any released version ofutopia-php/databaseyet.composer.jsonis pinned to the PR branch and must be reset to the proper release version (^5.X.Y) once #852 merges andutopia-php/databaseships a release.This PR should stay in draft until then.
Test plan
testCreateCSVImportSkipDuplicates,testCreateCSVImportOverwrite,testCreateCSVImportDefaultFailsOnDuplicate. All three pass locally against a full appwrite stack.Downstream PRs