-- Drop the view
DROP VIEW IF EXISTS department_hierarchy;

-- Drop the functions
DROP FUNCTION IF EXISTS get_department_hierarchy_path(UUID);
DROP FUNCTION IF EXISTS check_department_hierarchy();

-- Drop the trigger
DROP TRIGGER IF EXISTS check_department_hierarchy_trigger ON departments;

-- Drop the index
DROP INDEX IF EXISTS idx_departments_parent_id;

-- Remove the parent_department_id column
ALTER TABLE departments DROP COLUMN IF EXISTS parent_department_id;