mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
22ae9a2caf
* 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.
48 lines
1.3 KiB
PL/PgSQL
48 lines
1.3 KiB
PL/PgSQL
alter default privileges in schema content
|
|
revoke execute on functions from anon;
|
|
|
|
alter default privileges in schema content
|
|
revoke execute on functions from authenticated;
|
|
|
|
create function content.update_error_code(
|
|
code text,
|
|
service text,
|
|
http_status_code smallint default null,
|
|
message text default null
|
|
)
|
|
returns boolean
|
|
set search_path = ''
|
|
language plpgsql
|
|
as $$
|
|
#variable_conflict use_variable
|
|
declare
|
|
service_id uuid;
|
|
result boolean;
|
|
begin
|
|
insert into content.service (name)
|
|
values (service)
|
|
on conflict (name) do nothing;
|
|
|
|
select id into service_id
|
|
from content.service
|
|
where name = service;
|
|
|
|
insert into content.error (service, code, http_status_code, message)
|
|
values (service_id, code, http_status_code, message)
|
|
on conflict on constraint error_pkey do
|
|
update set
|
|
http_status_code = excluded.http_status_code,
|
|
message = excluded.message
|
|
where
|
|
error.service = service_id
|
|
and error.code = code
|
|
and (
|
|
error.http_status_code is distinct from excluded.http_status_code
|
|
or error.message is distinct from excluded.message
|
|
)
|
|
returning true into result;
|
|
|
|
return coalesce(result, false);
|
|
end;
|
|
$$;
|