fix(parties): skip companies frozen by a migration reset in the party backfill (#2176)

* fix(parties): skip companies frozen by a migration reset in the party backfill

Second prod failure of the substrate backfill: suppliers and customers in
a company archived by a migration reset are immutable
(block_migration_reset_source_mutation), so even setting party_id is
refused. Nine suppliers and eleven customers on prod. They are skipped;
the archive stays untouched by design.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(parties): pin why the party backfill skips migration-reset archives

A supplier in a company archived by a migration reset cannot take a
party_id: block_migration_reset_source_mutation refuses the UPDATE. The
backfill skip rule exists because of this trigger.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci(pg-upgrade): seed the rows that broke the party backfill on prod

A supplier and a customer with an empty name, and a company archived by a
migration reset whose rows are immutable. The substrate migration passed
the upgrade job and then failed twice on prod for exactly these shapes;
any migration that updates every supplier or customer now meets them in
CI first. The archived company is guarded on the table existing at the
merge-base.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-09-02 18:14:32 +02:00
committed by GitHub
co-authored by Claude Fable 5.1 Jakob Wennberg
parent a24982463b
commit c40e63e3f7
3 changed files with 98 additions and 0 deletions
@@ -306,6 +306,9 @@ GRANT EXECUTE ON FUNCTION public.ensure_party(uuid, uuid, text, text, text, text
-- party; nothing is merged on name. Rows with an empty name (three exist on
-- prod: one supplier, two customers) keep party_id NULL: ensure_party
-- refuses a nameless party, and the suggestion pipeline names them later.
-- Rows in a company archived by a migration reset (company_migration_resets
-- .source_company_id) are frozen by block_migration_reset_source_mutation
-- and are skipped too: that archive is immutable by design.
DO $$
DECLARE
r record;
@@ -315,6 +318,7 @@ BEGIN
FROM public.suppliers
WHERE party_id IS NULL AND company_id IS NOT NULL
AND nullif(btrim(name), '') IS NOT NULL
AND company_id NOT IN (SELECT source_company_id FROM public.company_migration_resets)
ORDER BY created_at, id
LOOP
UPDATE public.suppliers
@@ -327,6 +331,7 @@ BEGIN
FROM public.customers
WHERE party_id IS NULL AND company_id IS NOT NULL
AND nullif(btrim(name), '') IS NOT NULL
AND company_id NOT IN (SELECT source_company_id FROM public.company_migration_resets)
ORDER BY created_at, id
LOOP
UPDATE public.customers