Files
threshold/internal/db/schema/migrations/oss/postgres/57/01_auth.up.sql
T
Johan Brandhorst-Satzkorn eb113b5c9e fix(db): Reorder migrations (#2688)
Migration numbers need to be consistent between version upgrades.
The migrations for the key lifecycle management were merged
into v0.11.1 as number 56, but are currently 58 in main.
This reorders them down to 56, fixing an issue when
migrating from 0.11.1 to main.
2022-12-08 13:40:14 -05:00

33 lines
1.1 KiB
PL/PgSQL

begin;
-- This deletes the base type if the concrete types exist anymore.
delete from auth_account
where public_id not in
(select public_id
from auth_oidc_account)
and public_id not in
(select public_id
from auth_password_account);
-- delete_auth_account_subtype() is an after trigger function for subytypes of
-- auth_account.
-- this function is similar to the delete_auth_method_subtype account created
-- in 2/10_auth.up.sql
create function delete_auth_account_subtype() returns trigger
as $$
begin
delete from auth_account
where public_id = old.public_id;
return null; -- results are ignore since this is an after trigger.
end;
$$ language plpgsql;
comment on function delete_auth_account_subtype is
'delete_auth_account_subtype() is an after trigger function for subytypes of auth_account';
create trigger delete_auth_account_subtype after delete on auth_oidc_account
for each row execute procedure delete_auth_account_subtype();
create trigger delete_auth_account_subtype after delete on auth_password_account
for each row execute procedure delete_auth_account_subtype();
commit;