feat(migrate): onboarding backfill (repositories + dast_targets -> onboarded_targets) #141

Merged
sharang merged 2 commits from feat/onboarding-migration into main 2026-07-12 20:11:17 +00:00
2 Commits
Author SHA1 Message Date
Sharang ParnerkarandClaude Fable 5 0d83859bcf feat(migrate): per-tenant onboarding backfill + revert + CLI (#132 part 2)
CI / Check (pull_request) Successful in 8m15s
CI / Detect Changes (pull_request) Has been skipped
CI / Deploy Agent (pull_request) Has been skipped
CI / Deploy Dashboard (pull_request) Has been skipped
CI / Deploy Docs (pull_request) Has been skipped
CI / Deploy MCP (pull_request) Has been skipped
Wire the id-preserving mappers into a runnable, idempotent, reversible migration:
- backfill_onboarded_targets(db, dry_run): repositories -> onboarded_targets;
  dast_targets fold into the linked repo target (append LiveUrl, promote type,
  relink dast_scan_runs/pentest_sessions history) or migrate standalone. Skips
  existing (by _id), writes a schema_migrations marker; dry-run computes the
  report without writing. Legacy collections are never deleted.
- revert(db): replay the relink log, drop onboarded_targets + the log, clear the
  marker — restores the pre-migration state.
- CLI: `compliance-agent migrate onboarding [--all | --tenant <id>] [--dry-run]
  [--revert]`, with DatabasePool::list_tenant_ids for --all.
- database.rs: collection_named<T> accessor + list_tenant_ids helper.

Integration test (real Mongo, local-only — CI is --lib) covers fold + relink +
idempotency + revert end to end. 5 mapper unit tests run in CI.

Closes #132.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 19:49:52 +02:00
Sharang ParnerkarandClaude Fable 5 fa3a6b71fb feat(migrate): id-preserving mapping core for onboarding backfill (#132 part 1)
Pure transforms folding legacy records into the unified model, preserving _id so
every downstream collection keyed by that hex id keeps resolving:
- repo_to_target: TrackedRepository -> OnboardedTarget (GitRepo artifact with
  branch/watermark/auth; tracker config -> scan_config; webhook/schedule/counts).
- dast_to_artifact / dast_to_standalone_target: DastTarget -> LiveUrl artifact
  (crawl config + auth), or a standalone target when repo-less.
- fold_dast_into_target: append a LiveUrl to a repo-derived target (idempotent),
  promoting BackendService -> WebApp for a browser app.

5 unit tests. The per-tenant DB orchestration (idempotent backfill + revert) and
the `migrate onboarding` CLI subcommand are the next increment.

Refs #132.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 18:25:46 +02:00