Preserve usage provider identity

This commit is contained in:
fawney19
2026-05-20 20:56:36 +08:00
parent c972bbd397
commit 57910f906d
21 changed files with 340 additions and 104 deletions

View File

@@ -0,0 +1,18 @@
-- Usage is a historical fact table. Backfill nullable provider_id snapshots
-- from the unique provider name where the catalog row still exists.
UPDATE "usage"
SET provider_id = (
SELECT providers.id
FROM providers
WHERE providers.name = TRIM("usage".provider_name)
LIMIT 1
)
WHERE provider_id IS NULL
AND TRIM(COALESCE(provider_name, '')) <> ''
AND LOWER(TRIM(COALESCE(provider_name, ''))) NOT IN ('unknown', 'unknow', 'pending')
AND EXISTS (
SELECT 1
FROM providers
WHERE providers.name = TRIM("usage".provider_name)
);