CREATE  TABLE "doc_record_log" (
  -- 主键ID
  "record_id" int8 NOT NULL ,
  
  -- 实体类字段
  "definition_id" int8 NOT NULL,
  "definition_bus_no" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
  "content_json" text COLLATE "pg_catalog"."default" NOT NULL,
  "status_enum" int4 NOT NULL DEFAULT 0,
  "orgnization_id" int8 NOT NULL,
  "encounter_id" int8 NOT NULL,
  "patient_id" int8 NOT NULL,
  "record_time" timestamptz(6) NOT NULL,
  
  -- 继承的审计字段
  "tenant_id" int8 NOT NULL,
  "delete_flag" char(1) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '0',
  "create_by" varchar(32) COLLATE "pg_catalog"."default" NOT NULL DEFAULT '',
  "create_time" timestamptz(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "update_by" varchar(32) COLLATE "pg_catalog"."default",
  "update_time" timestamptz(6),
  
  -- 主键约束
  CONSTRAINT "doc_record_log_pkey" PRIMARY KEY ("record_id")
);

-- 3. 设置表所有者
ALTER TABLE "doc_record_log" OWNER TO "postgres";

-- 4. 表和字段注释
COMMENT ON TABLE "doc_record_log" IS '文书记录表';

COMMENT ON COLUMN "doc_record_log"."record_id" IS '主键ID';
COMMENT ON COLUMN "doc_record_log"."definition_id" IS '定义ID';
COMMENT ON COLUMN "doc_record_log"."definition_bus_no" IS '业务编码';
COMMENT ON COLUMN "doc_record_log"."content_json" IS '文档内容(JSON格式)';
COMMENT ON COLUMN "doc_record_log"."status_enum" IS '状态枚举: 0-草稿/暂存,1-提交,2-归档,3-修改';
COMMENT ON COLUMN "doc_record_log"."orgnization_id" IS '科室ID';
COMMENT ON COLUMN "doc_record_log"."encounter_id" IS '就诊记录ID';
COMMENT ON COLUMN "doc_record_log"."patient_id" IS '病人ID';
COMMENT ON COLUMN "doc_record_log"."record_time" IS '记录时间';
COMMENT ON COLUMN "doc_record_log"."tenant_id" IS '租户ID';
COMMENT ON COLUMN "doc_record_log"."delete_flag" IS '删除标志: 0-未删除,1-已删除';
COMMENT ON COLUMN "doc_record_log"."create_by" IS '创建人';
COMMENT ON COLUMN "doc_record_log"."create_time" IS '创建时间';
COMMENT ON COLUMN "doc_record_log"."update_by" IS '更新人';
COMMENT ON COLUMN "doc_record_log"."update_time" IS '更新时间';



-- 向迁移历史表插入记录
INSERT INTO __MigrationsHistory (MigrationId, ProductVersion)
VALUES ('202508221231 doc_record_log', '1.0.0');