Files
his/sql/迁移记录-DB变更记录/20260106_check_and_add_surgery_indication.sql

54 lines
1.5 KiB
SQL
Raw Permalink 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.

-- 检查并添加手术指征字段
-- 执行时间2025-01-06
-- 说明:修复手术指征字段无法保存或展示的问题
-- 1. 检查surgery_indication字段是否存在
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'cli_surgery'
AND column_name = 'surgery_indication'
) THEN
-- 字段不存在,添加该字段
ALTER TABLE cli_surgery ADD COLUMN surgery_indication TEXT;
-- 添加字段注释
COMMENT ON COLUMN cli_surgery.surgery_indication IS '手术指征';
RAISE NOTICE '已添加 surgery_indication 字段到 cli_surgery 表';
ELSE
RAISE NOTICE 'surgery_indication 字段已存在于 cli_surgery 表';
END IF;
END $$;
-- 2. 验证字段是否添加成功
SELECT
column_name,
data_type,
is_nullable,
column_default,
character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'cli_surgery'
AND column_name = 'surgery_indication';
-- 3. 查看最近的手术记录,检查surgery_indication字段是否有数据
SELECT
id,
surgery_no,
surgery_name,
surgery_indication,
create_time
FROM cli_surgery
WHERE delete_flag = '0'
ORDER BY create_time DESC
LIMIT 5;
-- 4. 更新说明
-- 手术指征字段已添加,可以正常保存和展示数据
-- 该字段为TEXT类型,可以存储较长的文本内容