diff --git a/server/skillhub-app/src/main/resources/db/migration/V42__identity_binding_cascade_delete.sql b/server/skillhub-app/src/main/resources/db/migration/V42__identity_binding_cascade_delete.sql new file mode 100644 index 00000000..e4c6284e --- /dev/null +++ b/server/skillhub-app/src/main/resources/db/migration/V42__identity_binding_cascade_delete.sql @@ -0,0 +1,7 @@ +-- identity_binding.user_id references user_account(id) without ON DELETE CASCADE. When an +-- account is removed, its bindings would otherwise survive and block the identity from being +-- provisioned again. Cascade the deletion so bindings never outlive their account. +ALTER TABLE identity_binding DROP CONSTRAINT identity_binding_user_id_fkey; +ALTER TABLE identity_binding + ADD CONSTRAINT identity_binding_user_id_fkey + FOREIGN KEY (user_id) REFERENCES user_account(id) ON DELETE CASCADE;