Repository navigation
Week 5: the sync engine keeps the target in step, safely - #6
Merged
Merged
Conversation
A migration is a one-time event; onboarding does not end there. Sync (src/firstsync/sync.py) is the ongoing half: it re-reads the source, rebuilds every row with the same build_row the dry-run and migration used, and applies only what changed - new records added, changed ones updated, the rest left alone. It runs behind the same approval gate (the mapping is what was approved and sync does not change it). Sync moves data only in the safe direction. Two situations are reported and otherwise left untouched, because both are a person's call, not onboarding's: - regressed: a record that loaded cleanly now fails validation in the source. The good target row is left intact - nobody wants onboarding to blank a live record. - vanished: a record in the target is no longer in the source. Reported, never deleted. Sync is idempotent: run it twice with no source change and the second run reports everything unchanged. It exits 2 (needs attention) vs 0 (quiet) so a scheduled run can page a human only when it should. The go-live report (src/firstsync/golive.py) is a plain-language view over the state the engines already wrote - approval, last dry-run, migration, latest sync - with a headline, what is live, and what is still open. It computes nothing new. New CLI: sync, report. New read-only tool: sync_get_status. DB gains external_ids() for vanished-record detection. 209 tests (11 new), mypy clean, no network, no API key. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ggB2HHn8zjybwfaJG1g3R
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.
What this adds
Onboarding doesn't end when the migration finishes — the source keeps changing. This PR is the ongoing-operations half.
The sync engine (
sync.py) re-reads the source, rebuilds every row with the samebuild_rowthe dry-run and migration use, and applies only what changed:It runs behind the same approval gate (the mapping is what a person approved; sync changes data, not the mapping). And it moves data only in the safe direction. Two situations it reports and otherwise touches nothing, because each is a human's call:
regressedvanishedIdempotent by construction (upsert on
(tenant, external_id)): a second sync with no source change reports everythingunchanged. Exit code is2when something needs attention,0when quiet — so a scheduled sync pages a human only when it should.The go-live report (
golive.py) is a plain-language view over the state the engines already wrote — approval, last dry-run, migration, latest sync. A headline, what's live, what's still open. It computes nothing new, so it's always consistent with the engines.Claude's only new capability:
sync_get_status— read-only. No tool approves, migrates, syncs, or deletes.Tests
209 passing (11 new),
mypy srcclean, no network, no API key. The sync tests mutate a source between runs — add a record (→ added), edit one (→ changed), delete one (→ vanished, target untouched), blank a required field (→ regressed, target untouched) — and the report tests check the full onboarding is reflected.Caveat
Sync reads up to
--limitrecords per object (default 2000). A source larger than the limit is read only in part, so a true vanished-record picture needs the limit to exceed the object's size. Real Salesforce CDC (streaming change events) is the production path and is noted, not built — same posture as the live REST client.Generated by Claude Code