ether-pms/sql/V4__dept_extension.sql

33 lines
1.3 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================
-- V4__dept_extension.sql
-- 部门扩展脚本
-- 添加部门类型字段
-- 添加项目员工的部门关联
-- ============================================================
BEGIN;
-- ============================================================
-- 1. 扩展 dept 表 - 添加部门类型
-- ============================================================
ALTER TABLE dept ADD COLUMN IF NOT EXISTS dept_type VARCHAR(20) DEFAULT 'ADMIN';
COMMENT ON COLUMN dept.dept_type IS '部门类型ADMIN-行政管理、ENGINEERING-工程部、SECURITY-安保部、CS-客服部、CLEANING-保洁部';
-- ============================================================
-- 2. 扩展 project_staff 表 - 添加部门关联
-- ============================================================
ALTER TABLE project_staff ADD COLUMN IF NOT EXISTS dept_id UUID REFERENCES dept(id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_project_staff_dept ON project_staff(dept_id);
-- ============================================================
-- 3. 更新 enterprise_user 表的部门关联为非空(企业员工必须有部门)
-- ============================================================
-- 注意已有数据的dept_id可能为NULL需要先处理
COMMIT;