-- File: trig_a_d_syst_credentials_delete_identity.eex.sql
-- Location: musebms/database/components/system/mscmp_syst_authn/ms_syst_data/syst_credentials/trig_a_d_syst_credentials_delete_identity.eex.sql
-- Project: Muse Systems Business Management System
--
-- Copyright © Lima Buttgereit Holdings LLC d/b/a Muse Systems
-- This file may include content copyrighted and licensed from third parties.
--
-- See the LICENSE file in the project root for license terms and conditions.
-- See the NOTICE file in the project root for copyright ownership information.
--
-- muse.information@musesystems.com :: https://muse.systems
DECLARE
BEGIN
-- Note that currently for all credential types which expect a
-- credential_for_identity_id value, the correct course of action here is to
-- delete the associated identity record. If this assumption should change,
-- such as if we should directly associate email identities with password
-- credentials, this logic will need to consider the credential type since
-- emails would not be deleted in all scenarios (passwords are recoverable).
DELETE FROM ms_syst_data.syst_identities WHERE id = old.credential_for_identity_id;
RETURN NULL;
END;