Skip to content

Week 5: the sync engine keeps the target in step, safely - #6

Merged
TAM-DS merged 1 commit into
mainfrom
week-5-sync
Nov 14, 2026
Merged

TAM-DS merged 1 commit into
mainfrom
week-5-sync

Conversation

@TAM-DS

@TAM-DS TAM-DS commented Nov 14, 2026

Copy link
Copy Markdown
Owner

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 same build_row the dry-run and migration use, and applies only what changed:

firstsync sync org_d --db out.db     # add new, update changed, leave the rest
firstsync report org_d               # where the onboarding stands, in plain language

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:

sync finds meaning sync's action
regressed a record that loaded cleanly now fails validation in the source leaves the good target row intact — onboarding never blanks a live record
vanished a target record is no longer in the source reports it — deleting is the admin's decision

Idempotent by construction (upsert on (tenant, external_id)): a second sync with no source change reports everything unchanged. Exit code is 2 when something needs attention, 0 when 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.

387 record(s) live; 1 open item(s).
Approved by tracy — 29 field(s).
Migration: 387 inserted, 9 skipped.
Latest sync: 0 added, 0 changed, 0 regressed, 0 vanished.
Open items:
  - 5 field(s) approved with an open question: ...

Claude's only new capability: sync_get_status — read-only. No tool approves, migrates, syncs, or deletes.

Tests

209 passing (11 new), mypy src clean, 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 --limit records 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

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
@TAM-DS
TAM-DS merged commit 8c03e20 into main Nov 14, 2026
1 check passed
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.

2 participants