Implement cleanup of orphaned user_param_visibility entries before schema updates in syncDatabase functions
This commit is contained in:
23
backend/sql/cleanup_orphaned_user_param_visibility.sql
Normal file
23
backend/sql/cleanup_orphaned_user_param_visibility.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- Cleanup script: Entfernt verwaiste Einträge aus user_param_visibility
|
||||
-- Diese Einträge verweisen auf nicht existierende user_param Einträge
|
||||
-- und verhindern das Hinzufügen des Foreign Key Constraints
|
||||
|
||||
BEGIN;
|
||||
|
||||
-- Lösche alle user_param_visibility Einträge, deren param_id nicht mehr in user_param existiert
|
||||
DELETE FROM community.user_param_visibility
|
||||
WHERE param_id NOT IN (
|
||||
SELECT id FROM community.user_param
|
||||
);
|
||||
|
||||
-- Zeige an, wie viele Einträge gelöscht wurden
|
||||
DO $$
|
||||
DECLARE
|
||||
deleted_count INTEGER;
|
||||
BEGIN
|
||||
GET DIAGNOSTICS deleted_count = ROW_COUNT;
|
||||
RAISE NOTICE 'Gelöschte verwaiste Einträge: %', deleted_count;
|
||||
END $$;
|
||||
|
||||
COMMIT;
|
||||
|
||||
Reference in New Issue
Block a user