Aller au contenu

Special purpose vehicule

A SPV is a project-owner company with its Lemonway KYB onboarding (v2 account + profile, or frozen v1 wallet). A project's cash wallet is properties.lemonwayWalletExternalId, never the SPV JSON — see the lemonway-project-wallet rule.

Company uniqueness (1 société = 1 SPV) is enforced on project_owner_company, not here — a siren for a French company, a country + registration number otherwise. The SPV table is transitional and carries no dedup guard of its own.

Deduplicating existing SPVs — special-purpose-vehicule-dedup script

Devtool script (scripts/special-purpose-vehicule-dedup/), --dry-run by default; --no-dry-run to apply, run as an ops step with Doppler prod config. Safe post-PDP-197: it never touches a project's cash wallet.

The plan is frozen data, not an algorithm (special-purpose-vehicule-dedup.data.ts): the exact survivors and deletions, decided once on the production clone and reviewed. The script never recomputes who to keep — it re-checks the frozen plan against live data and aborts on any drift.

  • Pass 1 — same Lemonway account: PASS1_MERGES lists, per account, the survivor and the SPVs it absorbs; their projects and wires are repointed to the survivor, the rest are hard-deleted. A divergent projectOwnerId blocks the merge unless ops validated it as the same company, in which case the merge carries allowDivergentOwner: true.
  • Pass 2 — projectless cross-identity duplicate: PASS2_DELETES — SPVs with no project whose company is served by an active SPV under another Lemonway identity, hard-deleted.
  • Pass 3 — out of scope: the same company active under several Lemonway accounts is a Lemonway regrouping topic, not code. The script never merges these.
  • Wires: every property_echeancier_wire_to_be_assigned.spvId is reset to the current owner of its project (deterministic rule).
  • Safety: assertPlanIsSafe fails fast when a row drifted (missing/extra member, divergent owner, a survivor missing an absorbed field, or a project the plan does not repoint still using a deleted SPV as its cash wallet — a pass-1 project keeps its absorbed SPV's wallet id, which is expected).
  • Recoverability: before deleting, every removed SPV (full JSON) is dumped to a timestamped CSV — keep it until the cleanup is confirmed, then discard it (it holds PII). No audit table.