You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
chore(db): backfill purchase_history.cloud_account_id from (provider, external_id) #22
Follow-up to the account-filter representation fix
The account-filter fix (rows 305/306/384/431/452, issues LeanerCloud/cloud-commitments-cli#701/#498/#866) resolves filtering by matching BOTH purchase_history.cloud_account_id (UUID) and account_id (provider external id) at query time, because cloud_account_id is NULL on many rows (migration 000011 added it without a backfill; direct-execute / ambient / legacy write paths leave it NULL).
This issue tracks the optional one-time backfill to converge historical rows onto the UUID column so future code can rely on it:
UPDATE purchase_history ph
SET cloud_account_id =ca.idFROM cloud_accounts ca
WHEREph.account_id=ca.external_idANDph.provider=ca.providerANDph.cloud_account_id IS NULL;
Notes / risks
Must match on (provider, external_id) (the cloud_accounts UNIQUE(provider, external_id) constraint), NOT external_id alone, to avoid cross-provider/tenant collisions.
Not required for correctness (the resolve-at-query fix handles it); this is cleanup/convergence only.
After backfill + a soak period, the dual-column predicate could be simplified back to UUID-only (separate change).
Acceptance criteria
Migration backfills cloud_account_id for all rows with a resolvable (provider, external_id).
Rows with no matching cloud_accounts entry are left NULL (and still filterable via the external-id branch).
A test verifies the backfill maps correctly and does not mis-assign across providers.
Activity
IAmJSD commentedon Oct 20, 2026
Claiming: working on this
chore(db): backfill purchase_history.cloud_account_id from (provider,…