Files
his/sql/迁移记录-DB变更记录/202601090000 add_identifier_no_column.sql

33 lines
1.1 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.

-- 检查并添加 adm_patient_identifier 表的 identifier_no 列(如果不存在)
-- 执行方式使用Navicat Premium或其他PostgreSQL客户端工具连接到数据库后执行
-- 检查列是否存在,如果不存在则添加
DO $$
BEGIN
-- 检查列是否存在
IF NOT EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'hisdev'
AND table_name = 'adm_patient_identifier'
AND column_name = 'identifier_no'
) THEN
-- 如果列不存在,则添加列
ALTER TABLE adm_patient_identifier
ADD COLUMN identifier_no VARCHAR(255);
-- 添加注释
COMMENT ON COLUMN adm_patient_identifier.identifier_no IS '标识号(就诊卡号)';
RAISE NOTICE '已添加 identifier_no 列';
ELSE
RAISE NOTICE 'identifier_no 列已存在,无需添加';
END IF;
END $$;
-- 插入迁移记录
INSERT INTO "__migrationshistory" ("version", "description")
VALUES ('202601090000 add_identifier_no_column', '1.0.0')
ON CONFLICT (version) DO NOTHING;