mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
Preserve usage provider identity
This commit is contained in:
@@ -4427,21 +4427,6 @@ END $mig$;
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Name: usage usage_provider_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
DO $mig$ BEGIN
|
||||
ALTER TABLE ONLY public.usage
|
||||
ADD CONSTRAINT usage_provider_id_fkey FOREIGN KEY (provider_id) REFERENCES public.providers(id) ON DELETE SET NULL;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN NULL;
|
||||
WHEN duplicate_table THEN NULL;
|
||||
WHEN invalid_table_definition THEN NULL;
|
||||
END $mig$;
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Name: usage usage_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
-- Usage is a historical fact table. Keep the provider_id snapshot even if the
|
||||
-- provider catalog row is deleted, and backfill rows that can still be matched
|
||||
-- by the unique provider name.
|
||||
|
||||
UPDATE public.usage AS usage_rows
|
||||
SET provider_id = providers.id
|
||||
FROM public.providers AS providers
|
||||
WHERE usage_rows.provider_id IS NULL
|
||||
AND BTRIM(COALESCE(usage_rows.provider_name, '')) <> ''
|
||||
AND lower(BTRIM(COALESCE(usage_rows.provider_name, ''))) NOT IN ('unknown', 'unknow', 'pending')
|
||||
AND providers.name = BTRIM(usage_rows.provider_name);
|
||||
|
||||
ALTER TABLE ONLY public.usage
|
||||
DROP CONSTRAINT IF EXISTS usage_provider_id_fkey;
|
||||
Reference in New Issue
Block a user