-- ----------------------------
-- Table structure for ck_alarm_config
-- ----------------------------
DROP TABLE IF EXISTS ck_alarm_config;
CREATE TABLE ck_alarm_config (
    SID bigint NOT NULL,
    ALARM_NAME varchar(255)  NULL DEFAULT NULL,
    THRESHOLD_TYPE char(1)  NULL DEFAULT NULL,
    THRESHOLD_RELATION varchar(64)  NULL DEFAULT NULL,
    THRESHOLD_VALUE varchar(10)  NULL DEFAULT NULL,
    ALARM_LEVEL char(1)  NULL DEFAULT NULL,
    STATE char(1)  NULL DEFAULT NULL,
    DELETED char(1)  NOT NULL,
    CREATE_BY varchar(255)  NOT NULL,
    CREATE_TIME timestamp NOT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    MESSAGETYPE int NULL DEFAULT NULL,
    STANDBY varchar(255)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_alarm_config IS 'CK_ALARM_CONFIG';
COMMENT ON COLUMN ck_alarm_config.THRESHOLD_TYPE IS '1、数值 2、百分比';
COMMENT ON COLUMN ck_alarm_config.THRESHOLD_RELATION IS 'gt代表> eq代表= lt代表<';
COMMENT ON COLUMN ck_alarm_config.ALARM_LEVEL IS '1、一般 2、中等 3、严重';
COMMENT ON COLUMN ck_alarm_config.STATE IS '1、新增 2、生效 9、挂起';
ALTER TABLE ck_alarm_config ADD CONSTRAINT ck_alarm_config_pkey PRIMARY KEY (SID);

alter table ck_alarm_config alter column DELETED set default 0;



-- ----------------------------
-- Table structure for ck_alarm_record
-- ----------------------------
DROP TABLE IF EXISTS ck_alarm_record;
CREATE TABLE ck_alarm_record (
    SID bigint NOT NULL,
    RELATION_ID bigint NULL DEFAULT NULL,
    RELATION_TABLE varchar(10)  NULL DEFAULT NULL ,
    ALARM_SID bigint NULL DEFAULT NULL,
    CHECK_LOG_SID bigint,
    CONTENT varchar(1000)  NULL DEFAULT NULL,
    MESSAGE_SEND_RESULT varchar(255)  NULL DEFAULT NULL,
    RECEIVED_BY varchar(255)  NULL DEFAULT NULL,
    RECEIPT_TIME timestamp NULL DEFAULT NULL,
    STATE char(1)  NULL DEFAULT NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON TABLE ck_alarm_record IS '告警记录表';
COMMENT ON COLUMN ck_alarm_record.RELATION_TABLE IS 'TABLE:表检核、ITEM:nosql检核、COMMON:通用检核';
COMMENT ON COLUMN ck_alarm_record.STATE IS '提醒、不再提醒';
COMMENT ON COLUMN ck_alarm_record.DELETED IS '1删除，0不删除（默认0）';
ALTER TABLE ck_alarm_record ADD CONSTRAINT ck_alarm_record_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_calendar
-- ----------------------------
DROP TABLE IF EXISTS ck_calendar;
CREATE TABLE ck_calendar (
    CK_ID varchar(255)  NOT NULL,
    CK_NAME varchar(255)  NOT NULL,
    CK_DESC varchar(255)  NULL DEFAULT NULL,
    CK_YEAR int NOT NULL,
    CK_DATELIST text  NOT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
ALTER TABLE ck_calendar ADD CONSTRAINT ck_calendar_pkey PRIMARY KEY (CK_ID);


-- ----------------------------
-- Table structure for ck_check_log
-- ----------------------------
DROP TABLE IF EXISTS ck_check_log;
CREATE TABLE ck_check_log (
    SID bigint NOT NULL,
    METHOD_CONFIG_ID bigint NULL DEFAULT NULL,
    CHECK_TIME timestamp NULL DEFAULT NULL,
    CHECK_END_TIME timestamp NULL DEFAULT NULL,
    CHECK_DURATION varchar(10)  NULL DEFAULT NULL,
    JOB_ID bigint NULL DEFAULT NULL,
    JOB_LOG_ID bigint NULL DEFAULT NULL,
    CHECK_STATUS varchar(10)  NULL DEFAULT NULL,
    RESULT_ID varchar(64)  NULL DEFAULT NULL,
    ERROR_REMARK text  NULL
);
CREATE INDEX METHOD_CONFIG_ID ON ck_check_log USING btree (METHOD_CONFIG_ID);
CREATE INDEX JOB_LOG_ID ON ck_check_log USING btree (JOB_LOG_ID);
CREATE INDEX SID ON ck_check_log USING btree (SID);
ALTER TABLE ck_check_log ADD CONSTRAINT ck_check_log_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_check_log_latest
-- ----------------------------
DROP TABLE IF EXISTS ck_check_log_latest;
CREATE TABLE ck_check_log_latest (
	METHOD_CONFIG_ID BIGINT NOT NULL,
	LOG_SID BIGINT DEFAULT NULL
);
ALTER TABLE ck_check_log_latest ADD CONSTRAINT ck_check_log_latest_pkey PRIMARY KEY (METHOD_CONFIG_ID);


-- ----------------------------
-- Table structure for ck_check_result
-- ----------------------------
DROP TABLE IF EXISTS ck_check_result;
CREATE TABLE ck_check_result (
    SID bigint NOT NULL ,
    INDEX_SID bigint NULL DEFAULT NULL,
    CHECK_FREQUENCY varchar(5)  NULL DEFAULT NULL,
    CHECK_TIME timestamp NULL DEFAULT NULL,
    CHECK_END_TIME timestamp NULL DEFAULT NULL,
    CHECK_DURATION varchar(10)  NULL DEFAULT NULL,
    ERROR_NUM bigint NULL DEFAULT NULL,
    SUM_NUM bigint NULL DEFAULT NULL,
    RESOURCE_SID bigint NULL DEFAULT NULL,
    ITEM_SID bigint NULL DEFAULT NULL,
    ERROR_KEYWORD text  NULL,
    ERROR_VALUE text  NULL ,
    ERROR_REMARK text  NULL,
    SOURCE_DATE timestamp NULL DEFAULT NULL,
    ERROR_SOURCE1 varchar(200)  NULL DEFAULT NULL,
    ERROR_SOURCE2 varchar(100)  NULL DEFAULT NULL,
    ERROR_SOURCE3 varchar(50)  NULL DEFAULT NULL,
    METHOD_CONFIG_ID bigint NOT NULL,
    JOB_ID bigint NULL DEFAULT NULL,
    JOB_LOG_ID bigint NULL DEFAULT NULL,
    CHECK_RESULT_URL varchar(200)  NULL DEFAULT NULL,
    CHECK_STATUS varchar(10)  NULL DEFAULT NULL,
    CHECK_RESULT_PATH varchar(200)  NULL DEFAULT NULL,
    CHECK_RESULT text
);
COMMENT ON COLUMN ck_check_result.SID IS '主键';
COMMENT ON COLUMN ck_check_result.INDEX_SID IS '所属指标';
COMMENT ON COLUMN ck_check_result.CHECK_FREQUENCY IS '检核频率';
COMMENT ON COLUMN ck_check_result.CHECK_TIME IS '检核时间';
COMMENT ON COLUMN ck_check_result.CHECK_DURATION IS '检核时长';
COMMENT ON COLUMN ck_check_result.ERROR_NUM IS '错误总数';
COMMENT ON COLUMN ck_check_result.SUM_NUM IS '总次数';
COMMENT ON COLUMN ck_check_result.RESOURCE_SID IS '资源id';
COMMENT ON COLUMN ck_check_result.ITEM_SID IS '资源项id';
COMMENT ON COLUMN ck_check_result.ERROR_KEYWORD IS '错误数据关键字';
COMMENT ON COLUMN ck_check_result.ERROR_VALUE IS '错误数据关键字';
COMMENT ON COLUMN ck_check_result.SOURCE_DATE IS '归属日期';
COMMENT ON COLUMN ck_check_result.ERROR_SOURCE1 IS '错误数据来源目录';
COMMENT ON COLUMN ck_check_result.ERROR_SOURCE2 IS '错误数据来源资源';
COMMENT ON COLUMN ck_check_result.ERROR_SOURCE3 IS '错误数据来源定位';
COMMENT ON COLUMN ck_check_result.METHOD_CONFIG_ID IS '关联\检核规则配置表\的主键';
COMMENT ON COLUMN ck_check_result.JOB_ID IS '任务id';
COMMENT ON COLUMN ck_check_result.JOB_LOG_ID IS '日志id';
COMMENT ON COLUMN ck_check_result.CHECK_RESULT_URL IS '检核结果文件下载地址';
COMMENT ON COLUMN ck_check_result.CHECK_STATUS IS '检核状态 1 成功 0失败';
COMMENT ON COLUMN ck_check_result.CHECK_RESULT_PATH IS '检核结果上传路径';
COMMENT ON COLUMN ck_check_result.CHECK_RESULT IS '检核结果上传路径';
ALTER TABLE ck_check_result ADD CONSTRAINT ck_check_result_pkey PRIMARY KEY (SID);
CREATE INDEX index_ck_check_result ON ck_check_result USING btree (CHECK_TIME) ;
CREATE INDEX ck_check_result_METHOD_CONFIG_ID ON ck_check_result USING btree (METHOD_CONFIG_ID) ;
CREATE INDEX ck_check_result_JOB_LOG_ID ON ck_check_result USING btree (JOB_LOG_ID) ;


-- ----------------------------
-- Table structure for ck_check_result_latest
-- ----------------------------
DROP TABLE IF EXISTS ck_check_result_latest;
CREATE TABLE ck_check_result_latest (
    METHOD_CONFIG_ID bigint NOT NULL,
    JOB_ID bigint NULL DEFAULT NULL,
    MAX_JOB_LOG_ID bigint NULL DEFAULT NULL,
    MAX_CHECK_TIME timestamp NULL DEFAULT NULL
);
ALTER TABLE ck_check_result_latest ADD CONSTRAINT ck_check_result_latest_pkey PRIMARY KEY (METHOD_CONFIG_ID);


-- ----------------------------
-- Table structure for ck_frequency
-- ----------------------------
DROP TABLE IF EXISTS ck_frequency;
CREATE TABLE ck_frequency (
    NAME varchar(128)  NOT NULL,
    TYPE char(1)  NULL DEFAULT NULL,
    INTERVALNUM int NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    EXPRESSION varchar(255)  NULL DEFAULT NULL,
    DESCRIPTION varchar(255)  NULL DEFAULT NULL
);
COMMENT ON COLUMN ck_frequency.INTERVALNUM IS '如果是类型是周期性，间隔不允许为空，默认为1';
ALTER TABLE ck_frequency ADD CONSTRAINT ck_frequency_pkey PRIMARY KEY (NAME);


-- ----------------------------
-- Table structure for ck_general_config
-- ----------------------------
DROP TABLE IF EXISTS ck_general_config;
CREATE TABLE ck_general_config (
    SID bigint NOT NULL,
    CONFIG_TYPE char(1)  NULL DEFAULT NULL,
    CONFIG_NAME varchar(255)  NULL DEFAULT NULL,
    STATE char(1)  NOT NULL DEFAULT '1',
    DELETED char(1)  NOT NULL DEFAULT '0',
    CREATE_BY varchar(255)  NOT NULL,
    CREATE_TIME timestamp NOT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    STANDBY varchar(500)  NULL DEFAULT NULL,
    SCHEDULE_ID bigint NULL DEFAULT NULL,
    SCHEDULE_NAME varchar(128)  NULL DEFAULT NULL,
    PRINCIPAL varchar(255)  NULL DEFAULT NULL,
    ALARM_ID      bigint NULL DEFAULT NULL,
    CHECK_CONFIG  varchar(255) NULL DEFAULT NULL
);
COMMENT ON TABLE ck_general_config IS 'CK_GENERAL_CONFIG';
COMMENT ON COLUMN ck_general_config.CONFIG_TYPE IS '1、数据抖动 2、数据偏移 3、数据堆积 4、数据对照';
COMMENT ON COLUMN ck_general_config.STATE IS '1、新建 2、启用  3、停用';
COMMENT ON COLUMN ck_general_config.PRINCIPAL IS '责任人';
ALTER TABLE ck_general_config ADD CONSTRAINT ck_general_config_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_general_config_detail
-- ----------------------------
DROP TABLE IF EXISTS ck_general_config_detail;
CREATE TABLE ck_general_config_detail (
    SID bigint NOT NULL,
    CONFIG_ID bigint NOT NULL,
    RESOURCE_NAME varchar(2000)  NULL DEFAULT NULL,
    RESOURCE_ID bigint NULL DEFAULT NULL,
    DATA_SOURCE_NAME varchar(64)  NULL DEFAULT NULL,
    INSTANCE_CODE varchar(255)  NULL DEFAULT NULL,
    ITEM_CODE varchar(200)  NULL DEFAULT NULL,
    ITEM_NAME varchar(2000)  NULL DEFAULT NULL,
    TABLE_CODE varchar(128)  NULL DEFAULT NULL,
    EXT_CONDITION varchar(500)  NULL DEFAULT NULL,
    UP_THRESHOLD varchar(20)  NULL DEFAULT NULL,
    DOWN_THRESHOLD varchar(20)  NULL DEFAULT NULL,
    PERIOD int NULL DEFAULT NULL,
    PERIOD_TYPE char(1)  NULL DEFAULT NULL,
    ITEM_ID bigint NULL DEFAULT NULL,
    DATA_SOURCE_SID bigint NULL DEFAULT NULL,
    SCHEMA_CODE varchar(255)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_general_config_detail IS 'CK_GENERAL_CONFIG_DETAIL';
COMMENT ON COLUMN ck_general_config_detail.CONFIG_ID IS '与通用检核规则配置表SID关联';
COMMENT ON COLUMN ck_general_config_detail.RESOURCE_NAME IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（RESOURCE_NAME）关联';
COMMENT ON COLUMN ck_general_config_detail.RESOURCE_ID IS '与资产信息表（DA_RESOURCE_INFO)表的主键SID关联';
COMMENT ON COLUMN ck_general_config_detail.INSTANCE_CODE IS '与DS_RESOURCE_ITEM的INSTANCE_CODE关联';
COMMENT ON COLUMN ck_general_config_detail.ITEM_CODE IS '与资产数据项（DA_RESOURCE_ITEM）表中的数据资源项标识（ITEM_CODE）关联';
COMMENT ON COLUMN ck_general_config_detail.ITEM_NAME IS '与资产数据项（DA_RESOURCE_ITEM）表中的元数据项名称（ITEM_NAME）关联';
COMMENT ON COLUMN ck_general_config_detail.TABLE_CODE IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（TABLE_CODE）关联';
COMMENT ON COLUMN ck_general_config_detail.PERIOD_TYPE IS '1、天 2、小时 3、分钟';
ALTER TABLE ck_general_config_detail ADD CONSTRAINT ck_general_config_detail_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_general_result
-- ----------------------------
DROP TABLE IF EXISTS ck_general_result;
CREATE TABLE ck_general_result (
    SID bigint NOT NULL,
    CONFIG_ID bigint NOT NULL,
    AVERAGE_VALUE varchar(20)  NULL DEFAULT NULL,
    UP_THRESHOLD varchar(20)  NULL DEFAULT NULL,
    DOWN_THRESHOLD varchar(20)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    JOB_ID bigint NULL DEFAULT NULL,
    JOB_LOG_ID bigint NULL DEFAULT NULL,
    COUNT_OUT_OF_RANGE bigint NULL DEFAULT NULL,
    LOG_MESSAGE varchar(8000)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_general_result IS 'CK_GENERAL_RESULT';
COMMENT ON COLUMN ck_general_result.CONFIG_ID IS '关联通用检核规则配置表主键SID';
COMMENT ON COLUMN ck_general_result.COUNT_OUT_OF_RANGE IS '非法值组数';
ALTER TABLE ck_general_result ADD CONSTRAINT ck_general_result_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_general_result_detail
-- ----------------------------
DROP TABLE IF EXISTS ck_general_result_detail;
CREATE TABLE ck_general_result_detail (
    SID bigint NOT NULL,
    RESULT_SID bigint NOT NULL,
    DATA_SOURCE_NAME varchar(64)  NULL DEFAULT NULL,
    TABLE_CODE varchar(128)  NULL DEFAULT NULL,
    RESOURCE_ID bigint NULL DEFAULT NULL,
    RESOURCE_NAME varchar(2000)  NULL DEFAULT NULL,
    ITEM_CODE varchar(200)  NULL DEFAULT NULL,
    ITEM_NAME varchar(2000)  NULL DEFAULT NULL,
    ACTUAL_VALUE varchar(20)  NULL DEFAULT NULL,
    LINE_NUM varchar(20)  NULL DEFAULT NULL,
    INSTANCE_CODE varchar(255)  NULL DEFAULT NULL,
    EXT_CONDITION varchar(500)  NULL DEFAULT NULL,
    ITEM_ID bigint NULL DEFAULT NULL,
    DATA_SOURCE_SID bigint NULL DEFAULT NULL,
    SCHEMA_CODE varchar(255)  NULL DEFAULT NULL
);
COMMENT ON COLUMN ck_general_result_detail.RESULT_SID IS '关联通用检核结果表的SID';
COMMENT ON COLUMN ck_general_result_detail.TABLE_CODE IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（TABLE_CODE）关联';
COMMENT ON COLUMN ck_general_result_detail.RESOURCE_ID IS '与资产信息表（DA_RESOURCE_INFO)表的主键SID关联';
COMMENT ON COLUMN ck_general_result_detail.RESOURCE_NAME IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（RESOURCE_NAME）关联';
COMMENT ON COLUMN ck_general_result_detail.ITEM_CODE IS '与资产数据项（DA_RESOURCE_ITEM）表中的数据资源项标识（SID）关联';
COMMENT ON COLUMN ck_general_result_detail.ITEM_NAME IS '与资产数据项（DA_RESOURCE_ITEM）表中的元数据项名称（ITEM_NAME）关联';
ALTER TABLE ck_general_result_detail ADD CONSTRAINT ck_general_result_detail_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_group
-- ----------------------------
DROP TABLE IF EXISTS ck_group;
CREATE TABLE ck_group (
    SID bigint NOT NULL,
    GROUP_NAME varchar(128)  NULL DEFAULT NULL,
    UPPER_GROUP bigint NULL DEFAULT NULL,
    DESCRIPTION text  NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    UPPER_NAME varchar(128)  NULL DEFAULT NULL
);
COMMENT ON COLUMN ck_group.UPPER_GROUP IS '父节点id，一级节点为空';
COMMENT ON COLUMN ck_group.UPPER_NAME IS '简称';
CREATE INDEX INDEX_CK_GROUP_UPPERGROUP ON ck_group USING btree (GROUP_NAME);
ALTER TABLE ck_group ADD CONSTRAINT ck_group_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_group_relation
-- ----------------------------
DROP TABLE IF EXISTS ck_group_relation;
CREATE TABLE ck_group_relation (
    CONFIGSID bigint NOT NULL,
    CONFIGTYPE int NOT NULL ,
    GROUPSID bigint NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN ck_group_relation.CONFIGTYPE IS '1,检核规则，2，通用检核配置';
ALTER TABLE ck_group_relation ADD CONSTRAINT ck_group_relation_pkey PRIMARY KEY (CONFIGSID, CONFIGTYPE);


-- ----------------------------
-- Table structure for ck_index_info
-- ----------------------------
DROP TABLE IF EXISTS ck_index_info;
CREATE TABLE ck_index_info (
    SID bigint NOT NULL,
    INDEX_CODE varchar(128)  NULL DEFAULT NULL,
    INDEX_NAME varchar(128)  NULL DEFAULT NULL,
    CHECK_TYPE char(1)  NULL DEFAULT NULL,
    INDEX_LEVEL varchar(2)  NULL DEFAULT NULL,
    PARENT_SID varchar(40)  NULL DEFAULT NULL,
    INDEX_WEIGHT bigint NULL DEFAULT NULL,
    REMARK text  NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    ALARM_ID bigint NULL DEFAULT NULL,
    ALARM_NAME varchar(128)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_index_info IS '检核指标表';
COMMENT ON COLUMN ck_index_info.SID IS '主键';
COMMENT ON COLUMN ck_index_info.INDEX_CODE IS '指标代码';
COMMENT ON COLUMN ck_index_info.INDEX_NAME IS '指标名称';
COMMENT ON COLUMN ck_index_info.CHECK_TYPE IS '检核类型';
COMMENT ON COLUMN ck_index_info.INDEX_LEVEL IS '指标级别';
COMMENT ON COLUMN ck_index_info.PARENT_SID IS '上级指标ID';
COMMENT ON COLUMN ck_index_info.INDEX_WEIGHT IS '权重(百分制)';
COMMENT ON COLUMN ck_index_info.ALARM_ID IS '告警信息ID,关联告警信息id';
COMMENT ON COLUMN ck_index_info.ALARM_NAME IS '告警名称,关联告警信息名称';
ALTER TABLE ck_index_info ADD CONSTRAINT ck_index_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_index_weight_info
-- ----------------------------
DROP TABLE IF EXISTS ck_index_weight_info;
CREATE TABLE ck_index_weight_info (
    SID bigint NOT NULL,
    INDEX_SID bigint NULL DEFAULT NULL,
    INDEX_NAME varchar(128)  NULL DEFAULT NULL,
    START_VALUE bigint NULL DEFAULT NULL ,
    END_VALUE bigint NULL DEFAULT NULL,
    SCORE bigint NULL DEFAULT NULL ,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON TABLE ck_index_weight_info IS '标准权值设置表';
COMMENT ON COLUMN ck_index_weight_info.SID IS '主键';
COMMENT ON COLUMN ck_index_weight_info.INDEX_SID IS '标准主键SID';
COMMENT ON COLUMN ck_index_weight_info.INDEX_NAME IS '指标名称';
COMMENT ON COLUMN ck_index_weight_info.START_VALUE IS '起始值';
COMMENT ON COLUMN ck_index_weight_info.END_VALUE IS '结束值';
COMMENT ON COLUMN ck_index_weight_info.SCORE IS '分数';
ALTER TABLE ck_index_weight_info ADD CONSTRAINT ck_index_weight_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_knowledge_info
-- ----------------------------
DROP TABLE IF EXISTS ck_knowledge_info;
CREATE TABLE ck_knowledge_info (
    SID bigint NOT NULL,
    TITLE varchar(255)  NULL DEFAULT NULL,
    CONTENT text  NULL,
    TARGET varchar(255)  NULL DEFAULT NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    PREVIEW text  NULL,
    READNUM bigint NULL DEFAULT 0
);
ALTER TABLE ck_knowledge_info ADD CONSTRAINT ck_knowledge_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_knowledge_log
-- ----------------------------
DROP TABLE IF EXISTS ck_knowledge_log;
CREATE TABLE ck_knowledge_log (
    SID bigint NOT NULL,
    KNOWLEDGE_SID bigint NULL DEFAULT NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);


-- ----------------------------
-- Table structure for ck_method_config
-- ----------------------------
DROP TABLE IF EXISTS ck_method_config;
CREATE TABLE ck_method_config (
    SID bigint NOT NULL,
    NAME varchar(500)  NOT NULL,
    CODE varchar(255)  NULL DEFAULT NULL,
    CHECK_METHOD char(1)  NULL DEFAULT NULL,
    RESOURCE_ID bigint NULL DEFAULT NULL,
    RESOURCE_NAME varchar(2000)  NULL DEFAULT NULL,
    ITEM_ID bigint NULL DEFAULT NULL,
    ITEM_CODE varchar(255)  NULL DEFAULT NULL,
    ITEM_NAME varchar(2000)  NULL DEFAULT NULL,
    TABLE_CODE varchar(128)  NOT NULL,
    INSTANCE_CODE varchar(255)  NOT NULL,
    FULLSQL varchar(3000)  NULL DEFAULT NULL,
    WHERESQL varchar(3000)  NULL DEFAULT NULL,
    NUMSQL varchar(3000)  NULL DEFAULT NULL,
    CHECK_TYPE char(1)  NULL DEFAULT NULL,
    INDEX_ID bigint NULL DEFAULT NULL,
    INDEX_CODE varchar(128)  NULL DEFAULT NULL,
    INDEX_NAME varchar(128)  NULL DEFAULT NULL,
    SCHEDULE_ID bigint NULL DEFAULT NULL,
    SCHEDULE_NAME varchar(128)  NULL DEFAULT NULL,
    CONFIG_TYPE char(1)  NULL DEFAULT NULL,
    CHECK_TPL int NULL DEFAULT -1,
    CHECK_CONFIG text  NULL,
    IS_ALARM char(1)  DEFAULT 0,
    ALARM_ID bigint NULL DEFAULT NULL,
    ALARM_NAME varchar(128)  NULL DEFAULT NULL,
    ALARM_TIME timestamp NULL DEFAULT NULL,
    STATE char(1)  NOT NULL,
    DELETED char(1)  NOT NULL,
    CREATE_BY varchar(255)  NOT NULL,
    CREATE_TIME timestamp NOT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    STANDBY varchar(500)  NULL DEFAULT NULL,
    SHOW_FIELD varchar(2000)  NULL DEFAULT NULL,
    DATA_SOURCE_NAME varchar(255)  NULL DEFAULT NULL,
    DATA_SOURCE_SID bigint NULL DEFAULT NULL,
    RESOURCE_TYPE varchar(255)  NULL DEFAULT NULL,
    SCHEMA_CODE varchar(255)  NULL DEFAULT NULL,
    PRINCIPAL varchar(255)  NULL DEFAULT NULL,
    SINK_MODE varchar(64) NULL DEFAULT NULL,
    DATA_FROM varchar(64) NULL DEFAULT NULL
);
COMMENT ON TABLE ck_method_config IS '此表用于配置检核规则（即原检核方法配置）CK_METHOD_CONFIG';
COMMENT ON COLUMN ck_method_config.CHECK_METHOD IS '1、SQL检核 2、NOSQL检核';
COMMENT ON COLUMN ck_method_config.RESOURCE_ID IS '与资产信息表（DA_RESOURCE_INFO)表的主键SID关联';
COMMENT ON COLUMN ck_method_config.RESOURCE_NAME IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（RESOURCE_NAME）关联';
COMMENT ON COLUMN ck_method_config.ITEM_ID IS '与资产数据项（DA_RESOURCE_ITEM）表中的数据资源项标识（SID）关联';
COMMENT ON COLUMN ck_method_config.ITEM_CODE IS '与资产数据项（DA_RESOURCE_ITEM）表中的元数据项编码（ITEM_CODE）关联';
COMMENT ON COLUMN ck_method_config.ITEM_NAME IS '与资产数据项（DA_RESOURCE_ITEM）表中的元数据项名称（ITEM_NAME）关联';
COMMENT ON COLUMN ck_method_config.TABLE_CODE IS '与资产信息表（DA_RESOURCE_INFO)表的数据资源编码（TABLE_CODE）关联';
COMMENT ON COLUMN ck_method_config.INSTANCE_CODE IS '与DS_RESOURCE_ITEM的INSTANCE_CODE关联';
COMMENT ON COLUMN ck_method_config.FULLSQL IS '根据前端配置的信息，组装成的完整的SQL 如果条件中存在{CheckField}占位符，则需要替换为相应的字段名称';
COMMENT ON COLUMN ck_method_config.WHERESQL IS 'SQL配置方式中，用户输入的where的SQL语句';
COMMENT ON COLUMN ck_method_config.INDEX_ID IS '指标id（SQL检核配置需要写入）';
COMMENT ON COLUMN ck_method_config.CONFIG_TYPE IS '1、可视化配置   2、SQL配置';
COMMENT ON COLUMN ck_method_config.CHECK_TPL IS '检核模板';
COMMENT ON COLUMN ck_method_config.CHECK_CONFIG IS '检查配置JSON';
COMMENT ON COLUMN ck_method_config.IS_ALARM IS '1、自定义告警  0、默认使用检核指标配置的告警 默认是0';
COMMENT ON COLUMN ck_method_config.STATE IS '1、新建 2、启用 3、停用';
COMMENT ON COLUMN ck_method_config.SHOW_FIELD IS '显示字段';
COMMENT ON COLUMN ck_method_config.DATA_SOURCE_NAME IS '数据源名称';
COMMENT ON COLUMN ck_method_config.DATA_SOURCE_SID IS '数据源SID';
COMMENT ON COLUMN ck_method_config.RESOURCE_TYPE IS '资源类型';
COMMENT ON COLUMN ck_method_config.PRINCIPAL IS '责任人';
COMMENT ON COLUMN ck_method_config.SINK_MODE IS '结果输出方式';
COMMENT ON COLUMN ck_method_config.DATA_FROM IS '检核规则创建来源, 默认为NULL';
CREATE INDEX index_ck_method_config1 ON ck_method_config USING btree (DELETED) ;
CREATE INDEX index_ck_method_config ON ck_method_config USING btree (RESOURCE_ID) ;
ALTER TABLE ck_method_config ADD CONSTRAINT ck_method_config_pkey PRIMARY KEY (SID);
ALTER TABLE ck_method_config ALTER COLUMN DELETED SET DEFAULT 0;

-- ----------------------------
-- Table structure for ck_method_config_course
-- ----------------------------
DROP TABLE IF EXISTS ck_method_config_course;
CREATE TABLE ck_method_config_course  (
    SID bigint NOT NULL,
    METHOD_CONFIG_ID bigint NULL DEFAULT NULL,
    OPT char(2)  NULL DEFAULT NULL ,
    TABLE_CODE varchar(128)  NULL DEFAULT NULL,
    ITEM_CODE varchar(128)  NULL DEFAULT NULL,
    INSTANCE_CODE varchar(255)  NULL DEFAULT NULL,
    WILDCARD char(1)  NULL DEFAULT NULL,
    ACTUAL_VALUE varchar(128)  NULL DEFAULT NULL,
    STARTTIME varchar(20)  NULL DEFAULT NULL,
    ENDTIME varchar(20)  NULL DEFAULT NULL,
    DICT_ID varchar(20)  NULL DEFAULT NULL,
    ITEM_ID bigint NULL DEFAULT NULL,
    ITEM_NAME varchar(128)  NULL DEFAULT NULL,
    PRIMARY KEY (SID)
);
COMMENT ON TABLE ck_method_config_course IS '记录SQL检核配置过程的表。主要是记录可视化配置的信息';
COMMENT ON COLUMN ck_method_config_course.OPT IS '&&且 ||或';
COMMENT ON COLUMN ck_method_config_course.WILDCARD IS '前缀匹配、后缀匹配、全模糊匹配、等于、不等于、包含、不包含、大于、大于等于、小于、小于等于、区间（包括边界）、区间（不包括边界）、区间（包含前边界）、区间（包含后边界）';


-- ----------------------------
-- Table structure for ck_method_item
-- ----------------------------
DROP TABLE IF EXISTS ck_method_item;
CREATE TABLE ck_method_item (
    SID bigint NOT NULL,
    CONFIG_SID bigint NULL DEFAULT NULL ,
    INDEX_SID bigint NULL DEFAULT NULL ,
    PARENT_SID bigint NULL DEFAULT NULL,
    OPT varchar(10)  NULL DEFAULT NULL,
    RULE_SID bigint NULL DEFAULT NULL ,
    EXPRESSION varchar(200)  NULL DEFAULT NULL,
    IDENTIFIER varchar(200)  NULL DEFAULT NULL,
    CHECK_MODE char(1)  NULL DEFAULT NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    STANDBY varchar(500)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_method_item IS 'CK_METHOD_ITEM';
COMMENT ON COLUMN ck_method_item.CONFIG_SID IS '数据项ID';
COMMENT ON COLUMN ck_method_item.INDEX_SID IS '指标ID';
COMMENT ON COLUMN ck_method_item.PARENT_SID IS '父级ID';
COMMENT ON COLUMN ck_method_item.RULE_SID IS '规则ID';
ALTER TABLE ck_method_item ADD CONSTRAINT ck_method_item_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_result_detail
-- ----------------------------
DROP TABLE IF EXISTS ck_result_detail;
CREATE TABLE ck_result_detail (
    SID bigint NOT NULL,
    RESULTID bigint NULL DEFAULT NULL,
    CHECK_COLUMN varchar(1000)  NULL DEFAULT NULL,
    COLUMN1 varchar(500)  NULL DEFAULT NULL,
    COLUMN2 varchar(500)  NULL DEFAULT NULL,
    COLUMN3 varchar(500)  NULL DEFAULT NULL,
    COLUMN4 varchar(500)  NULL DEFAULT NULL,
    COLUMN5 varchar(500)  NULL DEFAULT NULL,
    COLUMN6 varchar(500)  NULL DEFAULT NULL,
    COLUMN7 varchar(500)  NULL DEFAULT NULL,
    COLUMN8 varchar(500)  NULL DEFAULT NULL,
    COLUMN9 varchar(500)  NULL DEFAULT NULL,
    COLUMN10 varchar(500)  NULL DEFAULT NULL,
    COLUMN11 varchar(500)  NULL DEFAULT NULL,
    COLUMN12 varchar(500)  NULL DEFAULT NULL,
    COLUMN13 varchar(500)  NULL DEFAULT NULL,
    COLUMN14 varchar(500)  NULL DEFAULT NULL,
    COLUMN15 varchar(500)  NULL DEFAULT NULL,
    COLUMN16 varchar(500)  NULL DEFAULT NULL,
    COLUMN17 varchar(500)  NULL DEFAULT NULL,
    COLUMN18 varchar(500)  NULL DEFAULT NULL,
    COLUMN19 varchar(500)  NULL DEFAULT NULL,
    COLUMN20 varchar(500)  NULL DEFAULT NULL,
    COLUMN21 varchar(500)  NULL DEFAULT NULL,
    COLUMN22 varchar(500)  NULL DEFAULT NULL,
    COLUMN23 varchar(500)  NULL DEFAULT NULL,
    COLUMN24 varchar(500)  NULL DEFAULT NULL,
    COLUMN25 varchar(500)  NULL DEFAULT NULL,
    COLUMN26 varchar(500)  NULL DEFAULT NULL,
    COLUMN27 varchar(500)  NULL DEFAULT NULL,
    COLUMN28 varchar(500)  NULL DEFAULT NULL,
    COLUMN29 varchar(500)  NULL DEFAULT NULL,
    COLUMN30 varchar(500)  NULL DEFAULT NULL,
    COLUMN31 varchar(500)  NULL DEFAULT NULL,
    COLUMN32 varchar(500)  NULL DEFAULT NULL,
    COLUMN33 varchar(500)  NULL DEFAULT NULL,
    COLUMN34 varchar(500)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    TYPE char(1)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_result_detail IS '检核结果明细表 CK_RESULT_DETAIL';
COMMENT ON COLUMN ck_result_detail.COLUMN1 IS '预留字段1';
COMMENT ON COLUMN ck_result_detail.COLUMN2 IS '预留字段2';
COMMENT ON COLUMN ck_result_detail.COLUMN3 IS '预留字段3';
COMMENT ON COLUMN ck_result_detail.COLUMN4 IS '预留字段4';
COMMENT ON COLUMN ck_result_detail.COLUMN5 IS '预留字段5';
COMMENT ON COLUMN ck_result_detail.TYPE IS '1字段名，2字段对应的值';
ALTER TABLE ck_result_detail ADD CONSTRAINT ck_result_detail_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_result_options
-- ----------------------------
DROP TABLE IF EXISTS ck_result_options;
CREATE TABLE ck_result_options (
    SID bigint NOT NULL,
    CHECK_METHOD char(1)  NOT NULL,
    RESULT_SID bigint NOT NULL,
    OPTION_SID bigint NOT NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    STANDBY varchar(500)  NULL DEFAULT NULL
);
COMMENT ON TABLE ck_result_options IS '检核结果与问题的对应关系表';
COMMENT ON COLUMN ck_result_options.CHECK_METHOD IS '1、SQL检核 2、NOSQL检核';
COMMENT ON COLUMN ck_result_options.OPTION_SID IS '关联damp库下的PO_OPTIONS表的SID';
ALTER TABLE ck_result_options ADD CONSTRAINT ck_result_options_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_rule_info
-- ----------------------------
DROP TABLE IF EXISTS ck_rule_info;
CREATE TABLE ck_rule_info (
    SID bigint NOT NULL,
    RULE_CODE varchar(30)  NOT NULL,
    RULE_NAME varchar(50)  NULL DEFAULT NULL,
    RULE_OPTION varchar(20)  NULL DEFAULT NULL,
    RULE_VALUE text  NULL,
    RULE_VALUE_TYPE char(1)  NULL DEFAULT NULL,
    EXPRESSION text  NULL,
    REMARK text  NULL,
    DELETED char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON TABLE ck_rule_info IS '数据检核规则';
COMMENT ON COLUMN ck_rule_info.RULE_CODE IS '规则编码';
COMMENT ON COLUMN ck_rule_info.RULE_NAME IS '规则名称';
COMMENT ON COLUMN ck_rule_info.RULE_OPTION IS '操作符，CK_RULE_OPTION 包含【=,!=,<,>,match,in等】';
COMMENT ON COLUMN ck_rule_info.RULE_VALUE IS '规则值，包含【具体值，正则表达式，表名.字段名 等】';
COMMENT ON COLUMN ck_rule_info.RULE_VALUE_TYPE IS '规则值类型，CK_RULE_VALUE_TYPE :包含【1为普通值；2为特殊值；3为码表值】';
COMMENT ON COLUMN ck_rule_info.EXPRESSION IS '根据操作符和规则值运算出来的最终表达式';
COMMENT ON COLUMN ck_rule_info.REMARK IS '备注';
COMMENT ON COLUMN ck_rule_info.DELETED IS '是否删除 0:否 1:是';
ALTER TABLE ck_rule_info ADD CONSTRAINT ck_rule_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ck_schedule_config
-- ----------------------------
DROP TABLE IF EXISTS ck_schedule_config;
CREATE TABLE ck_schedule_config (
    SID bigint NOT NULL,
    NAME varchar(128)  NULL DEFAULT NULL,
    JOB_ID int NULL DEFAULT NULL,
    JOB_GROUP int NULL DEFAULT NULL,
    TYPE char(1)  NULL DEFAULT NULL,
    INTERVALNUM int NULL DEFAULT NULL,
    STARTTIME varchar(20)  NULL DEFAULT NULL,
    JOB_HANDLER varchar(255)  NULL DEFAULT NULL,
    STATE char(1)  NOT NULL ,
    DELETED char(1)  NOT NULL,
    CREATE_BY varchar(255)  NOT NULL,
    CREATE_TIME timestamp NOT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    REMARK varchar(255)  NULL DEFAULT NULL,
    STANDBY varchar(500)  NULL DEFAULT NULL,
    CALENDAR varchar(255)  NULL DEFAULT NULL,
    FREQUENCY_NAME varchar(255)  NULL DEFAULT NULL,
    EXPRESSION varchar(255)  NULL DEFAULT NULL
);
COMMENT ON COLUMN ck_schedule_config.JOB_ID IS '关联xxljob任务的主键id';
COMMENT ON COLUMN ck_schedule_config.JOB_GROUP IS 'XXLJOB的执行器id';
COMMENT ON COLUMN ck_schedule_config.INTERVALNUM IS '如果是类型是周期性，间隔不允许为空，默认为1';
COMMENT ON COLUMN ck_schedule_config.JOB_HANDLER IS '任务类别';
COMMENT ON COLUMN ck_schedule_config.STATE IS '1、新建 2、启用 3、停用';
CREATE INDEX I_job_id1 ON ck_schedule_config USING btree (JOB_ID) ;
ALTER TABLE ck_schedule_config ADD CONSTRAINT ck_schedule_config_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for cl_classif_info
-- ----------------------------
DROP TABLE IF EXISTS cl_classif_info;
CREATE TABLE cl_classif_info (
    SID bigint NOT NULL,
    CLASSIF_NAME varchar(128)  NULL DEFAULT NULL,
    UPPER_CLASSIF bigint NULL DEFAULT NULL,
    SEQ varchar(1024)  NULL DEFAULT NULL,
    IS_LEAF char(1)  NULL DEFAULT NULL,
    DISPLAY_ORDER bigint NULL DEFAULT NULL,
    DESCRIPTION text  NULL,
    LEVEL_NUM bigint NULL DEFAULT NULL,
    CLASSIF_FULL_NAME varchar(500)  NULL DEFAULT NULL,
    CLASSIF_TYPE varchar(5)  NULL DEFAULT NULL,
    RESOURCE_MAPPING varchar(128)  NULL DEFAULT NULL,
    IS_AUTH char(1)  NULL DEFAULT NULL ,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    CLASSIFTEMPLATE varchar(255)  NULL DEFAULT NULL,
    SHOW_SCHEMA varchar(10)  NULL DEFAULT NULL,
    ABBR_NAME varchar(128)  NULL DEFAULT NULL
);
COMMENT ON COLUMN cl_classif_info.UPPER_CLASSIF IS '父节点id，一级节点为空';
COMMENT ON COLUMN cl_classif_info.SEQ IS '.11.22.33.';
COMMENT ON COLUMN cl_classif_info.IS_LEAF IS 'Y/N';
COMMENT ON COLUMN cl_classif_info.DISPLAY_ORDER IS '1、2、3...99';
COMMENT ON COLUMN cl_classif_info.LEVEL_NUM IS '1、2、3';
COMMENT ON COLUMN cl_classif_info.CLASSIF_FULL_NAME IS '一级名称-二级名称-叶子名称';
COMMENT ON COLUMN cl_classif_info.RESOURCE_MAPPING IS '自动映射数据资源';
COMMENT ON COLUMN cl_classif_info.IS_AUTH IS '确定该分类是否需要做鉴权 0:不需要 1:需要';
COMMENT ON COLUMN cl_classif_info.SHOW_SCHEMA IS '是否展示SCHEMA节点 0:否,1:是';
COMMENT ON COLUMN cl_classif_info.ABBR_NAME IS '简称';
CREATE INDEX IDEX_CLS_UPPERCLASSIF ON cl_classif_info USING btree (UPPER_CLASSIF);
CREATE UNIQUE INDEX IDEX_CLS_SEQ ON cl_classif_info USING btree (SEQ) ;
ALTER TABLE cl_classif_info ADD CONSTRAINT cl_classif_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for cl_data_classif
-- ----------------------------
DROP TABLE IF EXISTS cl_data_classif;
CREATE TABLE cl_data_classif (
    RESOURCE_ID bigint NOT NULL,
    CLASSIF_SID bigint NOT NULL,
    RESOURCE_TYPE char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN cl_data_classif.RESOURCE_ID IS '资源注册后，关联数据资源';
COMMENT ON COLUMN cl_data_classif.RESOURCE_TYPE IS '目录级、数据级、数据项级';
CREATE INDEX IDX_CDC_RESOURCE_ID ON cl_data_classif USING btree (RESOURCE_ID) ;
CREATE INDEX IDX_CDC_CLASSIF_SID ON cl_data_classif USING btree (CLASSIF_SID) ;
ALTER TABLE cl_data_classif ADD CONSTRAINT cl_data_classif_pkey PRIMARY KEY (RESOURCE_ID, CLASSIF_SID);


-- ----------------------------
-- Table structure for cl_data_level
-- ----------------------------
DROP TABLE IF EXISTS cl_data_level;
CREATE TABLE cl_data_level (
    RESOURCE_SID bigint NOT NULL,
    LEVEL_SID bigint NOT NULL,
    RESOURCE_TYPE char(1)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN cl_data_level.RESOURCE_SID IS '资源注册后，关联数据资源';
COMMENT ON COLUMN cl_data_level.RESOURCE_TYPE IS '0目录级、1数据级、2数据项级';
ALTER TABLE cl_data_level ADD CONSTRAINT cl_data_level_pkey PRIMARY KEY (RESOURCE_SID, LEVEL_SID);


-- ----------------------------
-- Table structure for cl_level_info
-- ----------------------------
DROP TABLE IF EXISTS cl_level_info;
CREATE TABLE cl_level_info (
    SID bigint NOT NULL,
    LEVEL_CODE bigint NULL DEFAULT NULL,
    LEVEL_NAME varchar(64)  NULL DEFAULT NULL,
    LEVEL_DESC varchar(128)  NULL DEFAULT NULL,
    UPPER_LEVEL bigint NULL DEFAULT NULL,
    LEVEL_NUM bigint NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN cl_level_info.UPPER_LEVEL IS '第一级时为空';
COMMENT ON COLUMN cl_level_info.LEVEL_NUM IS '1/2';
ALTER TABLE cl_level_info ADD CONSTRAINT cl_level_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for cl_resouce_count
-- ----------------------------
DROP TABLE IF EXISTS cl_resouce_count;
CREATE TABLE cl_resouce_count (
    sid bigint NOT NULL,
    TOTAL_NUM int NULL DEFAULT NULL,
    BATCH_NUMBER bigint NULL DEFAULT NULL
);
ALTER TABLE cl_resouce_count ADD CONSTRAINT cl_resouce_count_pkey PRIMARY KEY (sid);


-- ----------------------------
-- Table structure for cl_resouce_count_temp
-- ----------------------------
DROP TABLE IF EXISTS cl_resouce_count_temp;
CREATE TABLE cl_resouce_count_temp (
    sid bigint NOT NULL,
    TOTAL_NUM int NULL DEFAULT NULL,
    BATCH_NUMBER bigint NULL DEFAULT NULL
);
COMMENT ON COLUMN cl_resouce_count_temp.BATCH_NUMBER IS '批次号';
ALTER TABLE cl_resouce_count_temp ADD CONSTRAINT cl_resouce_count_temp_pkey PRIMARY KEY (sid);


-- ----------------------------
-- Table structure for cl_role_classif
-- ----------------------------
DROP TABLE IF EXISTS cl_role_classif;
CREATE TABLE cl_role_classif (
    ROLE_SID varchar(65)  NOT NULL,
    CLASSIF_SID bigint NOT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
ALTER TABLE cl_role_classif ADD CONSTRAINT cl_role_classif_pkey PRIMARY KEY (ROLE_SID, CLASSIF_SID);


-- ----------------------------
-- Table structure for cl_role_level
-- ----------------------------
DROP TABLE IF EXISTS cl_role_level;
CREATE TABLE cl_role_level (
    ROLE_SID varchar(65)  NOT NULL,
    LEVEL_SID bigint NOT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
ALTER TABLE cl_role_level ADD CONSTRAINT cl_role_level_pkey PRIMARY KEY (ROLE_SID, LEVEL_SID);


-- ----------------------------
-- Table structure for cof_dict_entry
-- ----------------------------
DROP TABLE IF EXISTS cof_dict_entry;
CREATE TABLE cof_dict_entry (
    ID varchar(64)  NOT NULL,
    CODE varchar(64)  NULL DEFAULT NULL,
    DICT_TYPE_ID varchar(64)  NULL DEFAULT NULL,
    NAME varchar(512)  NULL DEFAULT NULL ,
    DESCRIPTION varchar(256)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    TENANT_ID varchar(64)  NULL DEFAULT NULL,
    PARENT_ID varchar(64)  NULL DEFAULT NULL,
    LOCALE varchar(64)  NULL DEFAULT NULL,
    STATUS varchar(64)  NULL DEFAULT NULL,
    SORT_NO int NULL DEFAULT NULL ,
    IS_LEAF smallint NULL DEFAULT NULL,
    TREE_LEVEL int NULL DEFAULT NULL,
    SEQ varchar(256)  NULL DEFAULT NULL,
    IS_FIXED smallint NULL DEFAULT NULL
);
COMMENT ON TABLE cof_dict_entry IS '字典项';
COMMENT ON COLUMN cof_dict_entry.ID IS '字典项ID';
COMMENT ON COLUMN cof_dict_entry.CODE IS '字典项编码';
COMMENT ON COLUMN cof_dict_entry.DICT_TYPE_ID IS '字典类型ID';
COMMENT ON COLUMN cof_dict_entry.NAME IS '字典项名称';
COMMENT ON COLUMN cof_dict_entry.DESCRIPTION IS '描述';
COMMENT ON COLUMN cof_dict_entry.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN cof_dict_entry.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN cof_dict_entry.TENANT_ID IS '租户ID';
COMMENT ON COLUMN cof_dict_entry.PARENT_ID IS '父字典ID';
COMMENT ON COLUMN cof_dict_entry.LOCALE IS '默认语言';
COMMENT ON COLUMN cof_dict_entry.STATUS IS '状态';
COMMENT ON COLUMN cof_dict_entry.SORT_NO IS '排序字段';
COMMENT ON COLUMN cof_dict_entry.IS_LEAF IS '是否叶节点';
COMMENT ON COLUMN cof_dict_entry.TREE_LEVEL IS '层级';
COMMENT ON COLUMN cof_dict_entry.SEQ IS '序列码';
COMMENT ON COLUMN cof_dict_entry.IS_FIXED IS '是否固定，如果是，则数据不能修改，不能删除';
CREATE INDEX COF_DICT_ENTRY_INDEX_SEQ ON cof_dict_entry USING btree (SEQ) ;
CREATE INDEX COF_DICT_ENTRY_INDEX_NAME ON cof_dict_entry USING btree (NAME) ;
CREATE INDEX COF_DICT_ENTRY_INDEX_CODE ON cof_dict_entry USING btree (CODE) ;
ALTER TABLE cof_dict_entry ADD CONSTRAINT cof_dict_entry_pkey PRIMARY KEY (ID);


-- ----------------------------
-- Table structure for cof_dict_type
-- ----------------------------
DROP TABLE IF EXISTS cof_dict_type;
CREATE TABLE cof_dict_type (
    ID varchar(64)  NOT NULL,
    CODE varchar(64)  NULL DEFAULT NULL ,
    NAME varchar(128)  NULL DEFAULT NULL,
    DESCRIPTION varchar(256)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    TENANT_ID varchar(64)  NULL DEFAULT NULL,
    PARENT_ID varchar(64)  NULL DEFAULT NULL,
    LOCALE varchar(64)  NULL DEFAULT NULL ,
    SORT_NO int NULL DEFAULT NULL,
    IS_LEAF smallint NULL DEFAULT NULL,
    TREE_LEVEL int NULL DEFAULT NULL,
    SEQ varchar(256)  NULL DEFAULT NULL,
    IS_FIXED smallint NULL DEFAULT NULL
);
COMMENT ON TABLE cof_dict_type IS '字典类型';
COMMENT ON COLUMN cof_dict_type.ID IS '字典类型ID';
COMMENT ON COLUMN cof_dict_type.CODE IS '字典类型编码';
COMMENT ON COLUMN cof_dict_type.NAME IS '字典类型名称';
COMMENT ON COLUMN cof_dict_type.DESCRIPTION IS '描述';
COMMENT ON COLUMN cof_dict_type.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN cof_dict_type.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN cof_dict_type.TENANT_ID IS '租户ID';
COMMENT ON COLUMN cof_dict_type.PARENT_ID IS '父字典类型ID';
COMMENT ON COLUMN cof_dict_type.LOCALE IS '默认语言';
COMMENT ON COLUMN cof_dict_type.SORT_NO IS '排序字段';
COMMENT ON COLUMN cof_dict_type.IS_LEAF IS '是否叶节点';
COMMENT ON COLUMN cof_dict_type.TREE_LEVEL IS '层级';
COMMENT ON COLUMN cof_dict_type.SEQ IS '序列码';
COMMENT ON COLUMN cof_dict_type.IS_FIXED IS '是否固定，如果是，则数据不能修改，不能删除';
CREATE INDEX COF_DICT_TYPE_INDEX_SEQ ON cof_dict_type USING btree (SEQ) ;
CREATE INDEX COF_DICT_TYPE_INDEX_NAME ON cof_dict_type USING btree (NAME) ;
CREATE INDEX COF_DICT_TYPE_INDEX_CODE ON cof_dict_type USING btree (CODE) ;
ALTER TABLE cof_dict_type ADD CONSTRAINT cof_dict_type_pkey PRIMARY KEY (ID);


-- ----------------------------
-- Table structure for ds_data_config_mgr
-- ----------------------------
DROP TABLE IF EXISTS ds_data_config_mgr;
CREATE TABLE ds_data_config_mgr (
    SID bigint NOT NULL,
    CONFIGCODE varchar(50)  NOT NULL,
    CONFIGNAME varchar(50)  NOT NULL,
    CONFIGTYPE varchar(25)  NOT NULL,
    USERKEYTABFILE varchar(255)  NULL DEFAULT NULL,
    KRB5FILE varchar(255)  NULL DEFAULT NULL,
    HIVECLIENTPROPFILE varchar(255)  NULL DEFAULT NULL,
    HDFSSITEFILE varchar(255)  NULL DEFAULT NULL,
    CORESITEFILE varchar(255)  NULL DEFAULT NULL,
    HBASESITEFILE varchar(255)  NULL DEFAULT NULL,
    DESCRIPTION varchar(500)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    PATH_TYPE varchar(255)  NULL DEFAULT 'LOCAL',
    SFTP_PATH varchar(255)  NULL DEFAULT ''
);
COMMENT ON COLUMN ds_data_config_mgr.PATH_TYPE IS 'LOCAL/SFTP';
COMMENT ON COLUMN ds_data_config_mgr.SFTP_PATH IS 'SFTP_PATH';
ALTER TABLE ds_data_config_mgr ADD CONSTRAINT ds_data_config_mgr_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ds_data_source
-- ----------------------------
DROP TABLE IF EXISTS ds_data_source;
CREATE TABLE ds_data_source (
    SID bigint NOT NULL,
    DATA_SOURCE_NAME varchar(300)  NULL DEFAULT NULL,
    URL varchar(1000)  NULL DEFAULT NULL,
    DRIVER varchar(100)  NULL DEFAULT NULL,
    USER_NAME varchar(60)  NULL DEFAULT NULL,
    PWD varchar(255)  NULL DEFAULT NULL,
    SOURCE varchar(10)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    DATA_SOURCE_CODE varchar(255)  NULL DEFAULT NULL,
    METACUBE_DEFINE_NAME varchar(255)  NULL DEFAULT NULL,
    DATASOURCE_TYPE varchar(50)  NULL DEFAULT NULL,
    CONFIGMGR_SID varchar(65)  NULL DEFAULT NULL
);
COMMENT ON COLUMN ds_data_source.DATA_SOURCE_NAME IS '数据源名称';
COMMENT ON COLUMN ds_data_source.SOURCE IS '数据源来源：1：元数据:2：自建:3：同步';
ALTER TABLE ds_data_source ADD CONSTRAINT ds_data_source_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ds_hbase_mappping
-- ----------------------------
DROP TABLE IF EXISTS ds_hbase_mappping;
CREATE TABLE ds_hbase_mappping (
    sid bigint NOT NULL,
    hive_ds_id varchar(100)  NULL DEFAULT NULL,
    hive_ds_name varchar(100)  NULL DEFAULT NULL,
    hive_db_name varchar(100)  NULL DEFAULT NULL,
    hive_table varchar(100)  NULL DEFAULT NULL,
    hbase_ds_id varchar(100)  NULL DEFAULT NULL,
    hbase_ds_name varchar(100)  NULL DEFAULT NULL,
    hbase_namespace varchar(100)  NULL DEFAULT NULL,
    hbase_table varchar(100)  NOT NULL,
    storage_type varchar(20)  NULL DEFAULT 'string',
    column_mappings text  NULL,
    serde_properties text  NULL,
    tbl_properties varchar(1024)  NULL DEFAULT NULL,
    create_time timestamp NULL DEFAULT NULL,
    create_by varchar(255)  NULL DEFAULT NULL,
    update_time timestamp NULL DEFAULT NULL,
    update_by varchar(255)  NULL DEFAULT NULL
);
COMMENT ON TABLE ds_hbase_mappping IS 'HBase 映射表管理';
ALTER TABLE ds_hbase_mappping ADD CONSTRAINT ds_hbase_mappping_pkey PRIMARY KEY (sid);


-- ----------------------------
-- Table structure for ds_resource_info
-- ----------------------------
DROP TABLE IF EXISTS ds_resource_info;
CREATE TABLE ds_resource_info (
    TABLE_TAG varchar(255)  NULL DEFAULT NULL,
    SID bigint NOT NULL,
    RESOURCE_CODE varchar(64)  NULL DEFAULT NULL,
    RESOURCE_NAME varchar(2000)  NULL DEFAULT NULL,
    DIRECTORY_CODE varchar(64)  NULL DEFAULT NULL,
    DIRECTORY_NAME varchar(2000)  NULL DEFAULT NULL,
    AUTHORITY_UNIT varchar(128)  NULL DEFAULT NULL,
    SOURCE_TYPE bigint NULL DEFAULT NULL,
    OBTAIN_WAY bigint NULL DEFAULT NULL,
    APP_SYSTEM varchar(128)  NULL DEFAULT NULL,
    MANAGE_UNIT varchar(128)  NULL DEFAULT NULL,
    DATA_LOCATION varchar(32)  NULL DEFAULT NULL,
    STORAGE_CENTER varchar(32)  NULL DEFAULT NULL,
    STATUS char(1)  NULL DEFAULT NULL,
    DESCRIPTION varchar(2000)  NULL DEFAULT NULL,
    STORAGE_SCALE varchar(128)  NULL DEFAULT NULL,
    STORAGE_CYCLE varchar(128)  NULL DEFAULT NULL,
    UPDATE_CYCLE varchar(128)  NULL DEFAULT NULL,
    UPDATE_SCALE varchar(128)  NULL DEFAULT NULL,
    DATA_UPDATE_TIME timestamp NULL DEFAULT NULL,
    REGISTER_TIME timestamp NULL DEFAULT NULL,
    META_DIR_CODE varchar(128)  NULL DEFAULT NULL,
    SCHEMA_CODE varchar(128)  NULL DEFAULT NULL,
    TABLE_CODE varchar(128)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    DATA_SOURCE_NAME varchar(300)  NULL DEFAULT NULL,
    RESOURCE_TYPE varchar(20)  NULL DEFAULT NULL,
    INIT_SOLR char(1)  NULL DEFAULT NULL,
    DATA_ORGANIZATION bigint NULL DEFAULT NULL,
    LABEL_1 bigint NULL DEFAULT NULL,
    LABEL_2 bigint NULL DEFAULT NULL,
    LABEL_3 bigint NULL DEFAULT NULL,
    LABEL_4 bigint NULL DEFAULT NULL,
    LABEL_5 bigint NULL DEFAULT NULL,
    INSTANCE_ID varchar(128)  NULL DEFAULT NULL,
    ISPEAT varchar(64)  NULL DEFAULT NULL,
    TABLEDESC varchar(6000)  NULL DEFAULT NULL,
    DATAMODE varchar(255)  NULL DEFAULT NULL,
    WHYREPEAT varchar(500)  NULL DEFAULT NULL,
    DIFFERSERV varchar(255)  NULL DEFAULT NULL,
    TABLE_RECORD varchar(255)  NULL DEFAULT NULL,
    MAPPING_NUMBER varchar(200)  NULL DEFAULT NULL,
    MAPPING_FIELD varchar(200)  NULL DEFAULT NULL,
    DATA_TABLE_NUM varchar(255)  NULL DEFAULT NULL,
    DEPLOY_TYPE varchar(300)  NULL DEFAULT NULL,
    LAST_UPDATE_TIME varchar(100)  NULL DEFAULT NULL,
    FUNCTION_TEMPLATE varchar(255)  NULL DEFAULT NULL,
    SUB_FUNCTION_TEMPLATE varchar(255)  NULL DEFAULT NULL,
    IS_ACCESS varchar(255)  NULL DEFAULT NULL,
    mainDataId varchar(100)  NULL DEFAULT NULL,
    WHY_NEGATIVELIST varchar(255)  NULL DEFAULT NULL,
    IS_NEGATIVELIST varchar(255)  NULL DEFAULT NULL,
    ID varchar(100)  NULL DEFAULT NULL,
    mainTableId varchar(100)  NULL DEFAULT NULL,
    busi_type_num varchar(100)  NULL DEFAULT NULL,
    topic_num varchar(100)  NULL DEFAULT NULL,
    TABLE_NAMESPACE varchar(255)  NULL DEFAULT NULL,
    TABLE_NAME varchar(512)  NULL DEFAULT NULL,
    PRINCIPAL varchar(255)  NULL DEFAULT NULL
);
COMMENT ON TABLE ds_resource_info IS '存储数据资源基本信息，如数据名称等，与元数据的表对应';
COMMENT ON COLUMN ds_resource_info.STATUS IS '状态:  4已发布';
COMMENT ON COLUMN ds_resource_info.META_DIR_CODE IS '资源关联的表所在目录编码';
COMMENT ON COLUMN ds_resource_info.SCHEMA_CODE IS '资源关联的表所在库编码';
COMMENT ON COLUMN ds_resource_info.TABLE_CODE IS '资源关联的表编码';
COMMENT ON COLUMN ds_resource_info.DATA_SOURCE_NAME IS '数据源名称';
COMMENT ON COLUMN ds_resource_info.INIT_SOLR IS '是否已加入solr';
COMMENT ON COLUMN ds_resource_info.DATA_ORGANIZATION IS '数组组织ID';
COMMENT ON COLUMN ds_resource_info.LABEL_1 IS '数组组织-标签1ID';
COMMENT ON COLUMN ds_resource_info.LABEL_2 IS '数组组织-标签2ID';
COMMENT ON COLUMN ds_resource_info.LABEL_3 IS '数组组织-标签3ID';
COMMENT ON COLUMN ds_resource_info.LABEL_4 IS '数组组织-标签4ID';
COMMENT ON COLUMN ds_resource_info.LABEL_5 IS '数组组织-标签5ID';
COMMENT ON COLUMN ds_resource_info.ISPEAT IS '是否重复';
COMMENT ON COLUMN ds_resource_info.DATAMODE IS '数据生成方式';
COMMENT ON COLUMN ds_resource_info.WHYREPEAT IS '重复原因';
COMMENT ON COLUMN ds_resource_info.PRINCIPAL IS '责任人';
CREATE INDEX IDX_DRI_DATAORGANIZATION ON ds_resource_info USING btree (DATA_ORGANIZATION) ;
ALTER TABLE ds_resource_info ADD CONSTRAINT ds_resource_info_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for ds_resource_item
-- ----------------------------
DROP TABLE IF EXISTS ds_resource_item;
CREATE TABLE ds_resource_item (
    SID bigint NOT NULL,
    RESOURCE_SID bigint NULL DEFAULT NULL,
    ITEM_CODE varchar(200)  NULL DEFAULT NULL,
    ITEM_NAME varchar(2000)  NULL DEFAULT NULL,
    IS_QUERY char(1)  NULL DEFAULT NULL,
    QUERY_MATCH_TYPE varchar(128)  NULL DEFAULT NULL,
    IS_SUBSCRIBE char(1)  NULL DEFAULT NULL,
    SUBSCRIBE_MATCH_TYPE varchar(128)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    INSTANCE_ID varchar(255)  NULL DEFAULT NULL,
    SYNCDATE timestamp NULL DEFAULT NULL,
    SEQ bigint NULL DEFAULT NULL,
    ITEM_TYPE varchar(500)  NULL DEFAULT NULL,
    INSTANCE_CODE varchar(255)  NULL DEFAULT NULL,
    INSTANCE_NAME varchar(2000)  NULL DEFAULT NULL,
    COMMENTS varchar(5000)  NULL DEFAULT NULL,
    IS_PK varchar(255)  NULL DEFAULT NULL,
    IS_UNIQUE varchar(255)  NULL DEFAULT NULL,
    IS_FK varchar(255)  NULL DEFAULT NULL,
    IS_NULLABLE varchar(255)  NULL DEFAULT NULL,
    COLLENGTHS varchar(255)  NULL DEFAULT NULL,
    SCALES varchar(255)  NULL DEFAULT NULL,
    INITIAL_VALUE varchar(255)  NULL DEFAULT NULL,
    IS_SHARE varchar(255)  NULL DEFAULT NULL,
    IS_MASKING varchar(255)  NULL DEFAULT NULL,
    DATA_TYPE varchar(500)  NULL DEFAULT NULL,
    WHY_SHARE varchar(2000)  NULL DEFAULT NULL,
    DESEN_RULE varchar(500)  NULL DEFAULT NULL,
    STD_CODE varchar(255)  NULL DEFAULT NULL ,
    STORAGE_FORMAT varchar(255)  NULL DEFAULT NULL,
    IS_BASE varchar(255)  NULL DEFAULT NULL ,
    SOURCE_SYSTEM varchar(255)  NULL DEFAULT NULL,
    OWN_USER varchar(255)  NULL DEFAULT NULL ,
    SOURCE_TB_EN varchar(255)  NULL DEFAULT NULL,
    SOURCE_TB_CN varchar(255)  NULL DEFAULT NULL,
    SOURCE_TB_DESC text  NULL,
    SOURCE_COL_EN varchar(255)  NULL DEFAULT NULL,
    SOURCE_COL_CN varchar(255)  NULL DEFAULT NULL,
    SOURCE_COL_DESC text  NULL,
    REB_DEPT varchar(255)  NULL DEFAULT NULL ,
    BUS_DEPT_IS_CFM varchar(255)  NULL DEFAULT NULL,
    DATA_IS_CFM varchar(255)  NULL DEFAULT NULL ,
    LATEST_VER_NO varchar(255)  NULL DEFAULT NULL,
    LATEST_REVISION_NO varchar(255)  NULL DEFAULT NULL,
    CONSTRAINTS_KEY varchar(255)  NULL DEFAULT NULL ,
    status varchar(10)  NULL DEFAULT NULL,
    ID varchar(100)  NULL DEFAULT NULL,
    mainTableId varchar(100)  NULL DEFAULT NULL,
    mainDataId varchar(100)  NULL DEFAULT NULL,
    SOURCE_COL_TYPE varchar(100)  NULL DEFAULT NULL,
    principal varchar(255)  NULL DEFAULT NULL
);
COMMENT ON TABLE ds_resource_item IS '存储数据资源项信息，与元数据的列对应，其与数据资源信息表对应关系为多对1';
COMMENT ON COLUMN ds_resource_item.INSTANCE_ID IS '元数据id';
COMMENT ON COLUMN ds_resource_item.SYNCDATE IS '元数据同步时间';
COMMENT ON COLUMN ds_resource_item.INSTANCE_CODE IS '字段英文名';
COMMENT ON COLUMN ds_resource_item.INSTANCE_NAME IS '中文名';
COMMENT ON COLUMN ds_resource_item.COMMENTS IS '描述，注释';
COMMENT ON COLUMN ds_resource_item.IS_PK IS '是否主键';
COMMENT ON COLUMN ds_resource_item.IS_UNIQUE IS '是否唯一键';
COMMENT ON COLUMN ds_resource_item.IS_FK IS '是否外键';
COMMENT ON COLUMN ds_resource_item.IS_NULLABLE IS '是否为空';
COMMENT ON COLUMN ds_resource_item.COLLENGTHS IS '长度';
COMMENT ON COLUMN ds_resource_item.SCALES IS '小数位';
COMMENT ON COLUMN ds_resource_item.INITIAL_VALUE IS '默认值';
COMMENT ON COLUMN ds_resource_item.IS_SHARE IS '是否有条件共享';
COMMENT ON COLUMN ds_resource_item.IS_MASKING IS '是否脱敏';
COMMENT ON COLUMN ds_resource_item.DATA_TYPE IS '数据类型';
COMMENT ON COLUMN ds_resource_item.WHY_SHARE IS '不能共享原因';
COMMENT ON COLUMN ds_resource_item.DESEN_RULE IS '脱敏规则';
COMMENT ON COLUMN ds_resource_item.STD_CODE IS '标准编码';
COMMENT ON COLUMN ds_resource_item.STORAGE_FORMAT IS '存储格式';
COMMENT ON COLUMN ds_resource_item.IS_BASE IS '是否基线版';
COMMENT ON COLUMN ds_resource_item.SOURCE_SYSTEM IS '来源系统';
COMMENT ON COLUMN ds_resource_item.OWN_USER IS '所属用户';
COMMENT ON COLUMN ds_resource_item.SOURCE_TB_EN IS '源表英文名';
COMMENT ON COLUMN ds_resource_item.SOURCE_TB_CN IS '源字段中文名';
COMMENT ON COLUMN ds_resource_item.SOURCE_COL_EN IS '源表字段英文';
COMMENT ON COLUMN ds_resource_item.REB_DEPT IS '责任部门';
COMMENT ON COLUMN ds_resource_item.BUS_DEPT_IS_CFM IS '业务部门是否确认';
COMMENT ON COLUMN ds_resource_item.DATA_IS_CFM IS '数据是否落地';
COMMENT ON COLUMN ds_resource_item.LATEST_VER_NO IS '最新版本号';
COMMENT ON COLUMN ds_resource_item.LATEST_REVISION_NO IS '最终修订版本号';
COMMENT ON COLUMN ds_resource_item.CONSTRAINTS_KEY IS '约束键';
CREATE INDEX IDX_DSRI_INSTANCEID ON ds_resource_item USING btree (INSTANCE_ID) ;
CREATE INDEX IDX_DSRI_RESOURCESID ON ds_resource_item USING btree (RESOURCE_SID) ;
ALTER TABLE ds_resource_item ADD CONSTRAINT ds_resource_item_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for po_feedback
-- ----------------------------
DROP TABLE IF EXISTS po_feedback;
CREATE TABLE po_feedback (
    SID bigint NOT NULL,
    OPTIONID bigint NOT NULL,
    USERNAME varchar(32)  NOT NULL,
    FEEDBACK text  NOT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN po_feedback.CREATE_BY IS '创建时的userid';
COMMENT ON COLUMN po_feedback.UPDATE_BY IS '最后一次修改者的userid';
COMMENT ON COLUMN po_feedback.UPDATE_TIME IS '最后一次修改该记录的时间';
ALTER TABLE po_feedback ADD CONSTRAINT po_feedback_pkey PRIMARY KEY (SID);


-- ----------------------------
-- Table structure for po_files
-- ----------------------------
DROP TABLE IF EXISTS po_files;
CREATE TABLE po_files (
    SID serial NOT NULL PRIMARY KEY,
    RELID bigint NULL DEFAULT NULL,
    FILENAME varchar(64)  NOT NULL,
    ACTUALFILENAME varchar(64)  NOT NULL,
    FILEPATH varchar(255)  NULL DEFAULT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL
);
COMMENT ON COLUMN po_files.RELID IS '附件所关联的对象ID';
COMMENT ON COLUMN po_files.FILEPATH IS '可以使用 http://ip:port/files/文件名称 访问上传路径下的文件';
COMMENT ON COLUMN po_files.CREATE_BY IS '创建时的userid';
COMMENT ON COLUMN po_files.UPDATE_BY IS '最后一次修改者的userid';
COMMENT ON COLUMN po_files.UPDATE_TIME IS '最后一次修改该记录的时间';

-- ----------------------------
-- Table structure for po_options
-- ----------------------------
DROP TABLE IF EXISTS po_options;
CREATE TABLE po_options (
    SID bigint NOT NULL,
    TITLE varchar(32)  NOT NULL,
    SOURCE varchar(32)  NOT NULL,
    DATARESOURCE varchar(32)  NULL DEFAULT NULL,
    FIELD varchar(32)  NULL DEFAULT NULL,
    DESCRIPTION text  NOT NULL,
    STATUS char(1)  NOT NULL,
    USERNAME varchar(32)  NOT NULL,
    CREATE_BY varchar(255)  NULL DEFAULT NULL,
    UPDATE_BY varchar(255)  NULL DEFAULT NULL,
    CREATE_TIME timestamp NULL DEFAULT NULL,
    UPDATE_TIME timestamp NULL DEFAULT NULL,
    CONTACTINFO varchar(255)  NULL DEFAULT NULL
);
COMMENT ON COLUMN po_options.SOURCE IS '来源于静态参数 存静态参数的ID 有   质量检核  隐患  用户反馈 其他途径';
COMMENT ON COLUMN po_options.STATUS IS '0  未反馈 1  已反馈 9  已关闭';
COMMENT ON COLUMN po_options.CREATE_BY IS '创建时的userid';
COMMENT ON COLUMN po_options.UPDATE_BY IS '最后一次修改者的userid';
COMMENT ON COLUMN po_options.UPDATE_TIME IS '最后一次修改该记录的时间';
ALTER TABLE po_options ADD CONSTRAINT po_options_pkey PRIMARY KEY (SID);


drop table if exists dqms_operation_log;
create table dqms_operation_log

(
    id                   varchar(64) not null ,
    operator_id          varchar(64) ,
    operator_name        varchar(64) ,
    operate_type        int ,
    operate_date         timestamp ,
    target_type          varchar(64) ,
    target_model_id      varchar(64) ,
    target_model_name    varchar(64) ,
    message              text ,
    tenant_id            varchar(64) ,
    primary key (id)
);

COMMENT ON TABLE dqms_operation_log IS '操作日志';
COMMENT ON COLUMN dqms_operation_log.id IS '操作日志ID';
COMMENT ON COLUMN dqms_operation_log.operator_id IS '操作者ID';
COMMENT ON COLUMN dqms_operation_log.operator_name IS '操作者名称';
COMMENT ON COLUMN dqms_operation_log.operate_type IS '操作类型';
COMMENT ON COLUMN dqms_operation_log.operate_date IS '时间';
COMMENT ON COLUMN dqms_operation_log.target_type IS '目标类型';
COMMENT ON COLUMN dqms_operation_log.target_model_id IS '目标ID';
COMMENT ON COLUMN dqms_operation_log.target_model_name IS '目标名称';
COMMENT ON COLUMN dqms_operation_log.message IS '信息';
COMMENT ON COLUMN dqms_operation_log.tenant_id IS '租户ID';

CREATE INDEX DQMS_OPERATION_LOG_INDEX_OPERATOR ON DQMS_OPERATION_LOG(OPERATOR_NAME);
CREATE INDEX LOG_INDEX_OPERATE_TYPE ON DQMS_OPERATION_LOG(operate_type);
CREATE INDEX DQMS_OPERATION_LOG_INDEX_TARGET ON DQMS_OPERATION_LOG(TARGET_TYPE, TARGET_MODEL_ID, TARGET_MODEL_NAME);

DROP TABLE IF EXISTS DQMS_OPERATION_LOG_DETAIL;
CREATE TABLE DQMS_OPERATION_LOG_DETAIL
(
    ID                   varchar(64) not null,
    OLD_DATA_JSON        varchar,
    NEW_DATA_JSON        varchar,
    primary key (ID)
);

COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.ID IS '日志详情ID';
COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.OLD_DATA_JSON IS '旧值';
COMMENT ON COLUMN DQMS_OPERATION_LOG_DETAIL.NEW_DATA_JSON IS '新值';

COMMENT ON TABLE DQMS_OPERATION_LOG_DETAIL IS '操作日志详情';

-----------------------------
-- 组织机构评分
-----------------------------
DROP TABLE IF EXISTS DQMS_RATING_RESULT;
CREATE TABLE DQMS_RATING_RESULT(
                                   ID  NUMERIC(20,0) PRIMARY KEY,
                                   ORG_ID VARCHAR(64),
                                   ORG_NAME VARCHAR(50),
                                   ORG_LEVEL VARCHAR(2),
                                   PARENT_ORG_ID VARCHAR(64),
                                   SCORE NUMERIC(20,0),
                                   START_DATE TIMESTAMP,
                                   END_DATE TIMESTAMP,
                                   RATING_CYCLE VARCHAR(50),
                                   RATING_POINT VARCHAR(50),
                                   CREATE_TIME TIMESTAMP,
                                   CREATE_USER VARCHAR(25),
                                   LAST_MODIFIER_TIME TIMESTAMP,
                                   LAST_MODIFIER_USER VARCHAR(25)
);

COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_ID IS '组织ID';
COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_NAME IS '组织名';
COMMENT ON COLUMN DQMS_RATING_RESULT.ORG_LEVEL IS '组织等级';
COMMENT ON COLUMN DQMS_RATING_RESULT.PARENT_ORG_ID IS '父组织ID';
COMMENT ON COLUMN DQMS_RATING_RESULT.SCORE IS '得分';
COMMENT ON COLUMN DQMS_RATING_RESULT.START_DATE IS '评估开始日期';
COMMENT ON COLUMN DQMS_RATING_RESULT.END_DATE IS '评估截至日期';
COMMENT ON COLUMN DQMS_RATING_RESULT.RATING_CYCLE IS '评分周期 年（year）、季度（quarter）、月（month）、周（week），默认月';
COMMENT ON COLUMN DQMS_RATING_RESULT.RATING_POINT IS '评分点 例如：2023-01';







