-- Drop existing foreign key constraint with RESTRICT
DO $$
BEGIN
    IF EXISTS (
        SELECT 1
        FROM pg_constraint
        WHERE conname = 'fk_project_chickins_kandang'
        AND conrelid = 'project_chickins'::regclass
    ) THEN
        ALTER TABLE project_chickins
        DROP CONSTRAINT fk_project_chickins_kandang;
    END IF;
END $$;

-- Add new foreign key constraint with CASCADE delete
ALTER TABLE project_chickins
ADD CONSTRAINT fk_project_chickins_kandang
FOREIGN KEY (project_flock_kandang_id)
REFERENCES project_flock_kandangs(id)
ON DELETE CASCADE ON UPDATE CASCADE;
