Files
digital-psychology/apps/api/migrations/000026_crisis_policies.up.sql
T
jackyu66gitandCursor b7b0b18802 fix(db): 重编号合并后撞号 migration,并修 admin e2e base
将 015–023 双文件冲突线性化为 015–050;提供已有库 schema_migrations 修复脚本;admin Playwright 对齐 /psy/admin/ 预览路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 02:14:52 +08:00

50 lines
1.4 KiB
SQL

-- ECR-022 CrisisCare CrisisPolicy
CREATE TABLE IF NOT EXISTS crisis_policies (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
code varchar(64) NOT NULL UNIQUE,
title varchar(128) NOT NULL,
severity varchar(16) NOT NULL
CHECK (severity IN ('high','critical')),
pattern text NOT NULL,
action varchar(32) NOT NULL
CHECK (action IN ('escalate','block','show_helpline')),
helpline_text text NULL,
active boolean NOT NULL DEFAULT true,
system boolean NOT NULL DEFAULT false,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_crisis_policies_active ON crisis_policies(active);
INSERT INTO crisis_policies(code, title, severity, pattern, action, helpline_text, active, system)
VALUES
(
'self_harm_critical',
'自伤/轻生危机',
'critical',
'不想活了',
'show_helpline',
'若你正处于危机,请立即联系身边可信的人,或拨打当地紧急援助/心理援助热线。愈心谷不能替代急救与专业干预。',
true,
true
),
(
'violence_threat',
'暴力伤害威胁',
'high',
'弄死你',
'escalate',
NULL,
true,
true
)
ON CONFLICT (code) DO NOTHING;
INSERT INTO admin_role_permissions(role_id, code)
SELECT r.id, 'admin.crisis.read'
FROM admin_roles r
WHERE r.name = 'super_admin'
ON CONFLICT DO NOTHING;