Files
supabase__supabase/supabase/migrations/20250522171141_error_code_delete_function.sql
Charis 22ae9a2caf feat(db): error table updating function (#35819)
* feat(db): error table updating function

Add a function for updating the error table (to be used for syncing the
repo contents to the database).

* feat(db): add function to delete unused error codes

Add a DB function to delete any unused error codes (actually a soft
delete due to a rule on the content.error table). This allows syncing
the repo state to the DB state by removing any entries that have been
removed from the repo.
2025-05-27 10:05:40 -04:00

17 lines
437 B
PL/PgSQL

create or replace function content.delete_error_codes_except(
skip_codes jsonb
)
returns void
set search_path = ''
language sql
as $$
delete from content.error
where not exists (
select 1
from jsonb_array_elements(skip_codes) skipped
join content.service on service.name = (skipped ->> 'service')
where service.id = error.service
and error.code = (skipped ->> 'error_code')
);
$$;