Add migration to set user_id to null if EPerson no longer exists & enforce it for future

This commit is contained in:
Tim Donohue
2024-05-07 17:16:33 -05:00
parent 7d693bb53d
commit ef24645cbf
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--
-- If Process references an EPerson that no longer exists, set the "user_id" to null.
UPDATE process SET user_id = null WHERE NOT EXISTS (SELECT * FROM EPerson where uuid = process.user_id);
-- Add new constraint where process.user_id is nullified if referenced EPerson is deleted.
ALTER TABLE process ADD CONSTRAINT process_eperson FOREIGN KEY (user_id) REFERENCES EPerson(uuid) ON DELETE SET NULL;

View File

@@ -0,0 +1,13 @@
--
-- The contents of this file are subject to the license and copyright
-- detailed in the LICENSE and NOTICE files at the root of the source
-- tree and available online at
--
-- http://www.dspace.org/license/
--
-- If Process references an EPerson that no longer exists, set the "user_id" to null.
UPDATE process SET user_id = null WHERE NOT EXISTS (SELECT * FROM EPerson where uuid = process.user_id);
-- Add new constraint where process.user_id is nullified if referenced EPerson is deleted.
ALTER TABLE process ADD CONSTRAINT process_eperson FOREIGN KEY (user_id) REFERENCES EPerson(uuid) ON DELETE SET NULL;