Retroactively remap Versa-migration 8xxx leaves to Arcus native GL accounts
Retroactive cleanup helper for entities loaded with the under-covered
Phase 5A fold-rule set. For each item, transactionally swaps every
journal_entry_lines.gl_account_id reference from FROM to TO, then
optionally soft-deletes the FROM account.
Safety invariants (HARD BAR).
- Both accounts must belong to the API key’s entity.
- FROM must be a Versa-migration leaf: description must contain
versa_real_id=or “Migrated from Versa”. Native Arcus accounts never carry this tag, so this gate prevents the handler from ever touching a native account. - TO must have
system_account_key NOT NULL(must be a native Arcus account; remapping one 8xxx leaf to another is rejected). - Per-pair transaction with
SELECT ... FOR UPDATElocks on both accounts. - Pre/post snapshot of
journal_entry_lines.count + SUM(debit) + SUM(credit)for FROM is compared against TO’s delta; mismatch aborts the transaction so TB never drifts.
soft_delete_source. Optional. When true AND zero JE lines
remain pointing at FROM after the UPDATE (verified in-transaction),
the source account is soft-deleted with deleted_at = NOW() and
is_active = false. When a concurrent writer adds a JE line to
FROM between the UPDATE and the orphan check, the soft-delete is
skipped (the swap still committed).
Max 50 items per call (smaller cap than relink because each item locks the gl_account row + UPDATEs every JE line on it; large batches risk lock contention with concurrent posters).
Scope: migration:write.
Authorizations
API key issued per entity via Settings > Developers > API Keys.
Each key carries scopes (e.g. orders:read, products:write).
Bearer token format: Authorization: Bearer ark_live_ent_Test keys use ark_test_ent_. Both are issued per entity
via Settings > Developers > API Keys.
Headers
Path Parameters
Body
1 - 50 elements
