Compare commits
2 Commits
9523fe6650
...
4dd4138197
| Author | SHA1 | Date | |
|---|---|---|---|
| 4dd4138197 | |||
| 5ef059eb40 |
@@ -0,0 +1,15 @@
|
||||
-- 005_fix_user_scenarios_description.down.sql
|
||||
-- 回滚:恢复原约束(description 必填,prompt 最小长度 50)
|
||||
|
||||
-- 注意:如果表中存在不符合原约束的数据,此回滚会失败
|
||||
|
||||
-- 1. 恢复 description 为必填
|
||||
ALTER TABLE user_scenarios
|
||||
ALTER COLUMN description SET NOT NULL;
|
||||
|
||||
-- 2. 恢复 prompt 最小长度为 50
|
||||
ALTER TABLE user_scenarios
|
||||
DROP CONSTRAINT IF EXISTS check_prompt_length;
|
||||
|
||||
ALTER TABLE user_scenarios
|
||||
ADD CONSTRAINT check_prompt_length CHECK (char_length(prompt) >= 50 AND char_length(prompt) <= 2000);
|
||||
16
backend/migrations/005_fix_user_scenarios_description.up.sql
Normal file
16
backend/migrations/005_fix_user_scenarios_description.up.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- 005_fix_user_scenarios_description.up.sql
|
||||
-- 修复 user_scenarios 表约束:description 允许为空,prompt 最小长度改为 10
|
||||
|
||||
-- 1. 允许 description 为空
|
||||
ALTER TABLE user_scenarios
|
||||
ALTER COLUMN description DROP NOT NULL;
|
||||
|
||||
-- 2. 修复 prompt 长度约束(从 50 改为 10,与代码一致)
|
||||
ALTER TABLE user_scenarios
|
||||
DROP CONSTRAINT IF EXISTS check_prompt_length;
|
||||
|
||||
ALTER TABLE user_scenarios
|
||||
ADD CONSTRAINT check_prompt_length CHECK (char_length(prompt) >= 10 AND char_length(prompt) <= 2000);
|
||||
|
||||
COMMENT ON COLUMN user_scenarios.description IS '简短描述,可选,显示在情景卡片上(允许为空)';
|
||||
COMMENT ON COLUMN user_scenarios.prompt IS '角色 System Prompt,定义 AI 行为(10-2000 字符)';
|
||||
9
check_constraints.sql
Normal file
9
check_constraints.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- 检查 user_scenarios 表的所有约束
|
||||
SELECT
|
||||
con.conname AS constraint_name,
|
||||
con.contype AS constraint_type,
|
||||
pg_get_constraintdef(con.oid) AS constraint_definition
|
||||
FROM pg_constraint con
|
||||
JOIN pg_class rel ON rel.oid = con.conrelid
|
||||
WHERE rel.relname = 'user_scenarios'
|
||||
ORDER BY con.conname;
|
||||
26
fix_user_scenarios.sql
Normal file
26
fix_user_scenarios.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
-- 快速修复脚本:修复 user_scenarios 表约束
|
||||
-- 在生产 PostgreSQL 容器中执行此文件
|
||||
|
||||
-- 1. 允许 description 为空
|
||||
ALTER TABLE user_scenarios
|
||||
ALTER COLUMN description DROP NOT NULL;
|
||||
|
||||
-- 2. 修复 prompt 长度约束(从 50 改为 10,与代码一致)
|
||||
ALTER TABLE user_scenarios
|
||||
DROP CONSTRAINT IF EXISTS check_prompt_length;
|
||||
|
||||
ALTER TABLE user_scenarios
|
||||
ADD CONSTRAINT check_prompt_length CHECK (char_length(prompt) >= 10 AND char_length(prompt) <= 2000);
|
||||
|
||||
-- 更新注释
|
||||
COMMENT ON COLUMN user_scenarios.description IS '简短描述,可选,显示在情景卡片上(允许为空)';
|
||||
COMMENT ON COLUMN user_scenarios.prompt IS '角色 System Prompt,定义 AI 行为(10-2000 字符)';
|
||||
|
||||
-- 验证修改
|
||||
SELECT
|
||||
con.conname AS constraint_name,
|
||||
pg_get_constraintdef(con.oid) AS constraint_definition
|
||||
FROM pg_constraint con
|
||||
JOIN pg_class rel ON rel.oid = con.conrelid
|
||||
WHERE rel.relname = 'user_scenarios'
|
||||
AND con.conname = 'check_prompt_length';
|
||||
Reference in New Issue
Block a user