-- ============================================================================
-- OARMS - CW-2 证据规则关联 DDL
-- Database: DM8 (达梦)
-- Schema: OARMS
-- Version: V8.0.0
-- Date: 2026-05-18
-- Description: 证据-规则关联表
-- ============================================================================

-- ----------------------------------------------------------------------------
-- 1. cw_evidence_rule_relation - 证据规则关联
-- ----------------------------------------------------------------------------
CREATE TABLE OARMS.CW_EVIDENCE_RULE_RELATION (
    id                VARCHAR(50)    NOT NULL,
    evidence_id       VARCHAR(50)    NOT NULL,
    rule_id           VARCHAR(50)    NOT NULL,
    associated_by     VARCHAR(50)    NOT NULL,
    associated_at     TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id)
);

-- 唯一约束(同一证据不能重复关联同一规则)
CREATE UNIQUE INDEX IDX_CW_EVID_RULE_UK ON OARMS.CW_EVIDENCE_RULE_RELATION (EVIDENCE_ID, RULE_ID);

-- 普通索引
CREATE INDEX IDX_CW_EVID_RULE_EVID ON OARMS.CW_EVIDENCE_RULE_RELATION (EVIDENCE_ID);
CREATE INDEX IDX_CW_EVID_RULE_RULE ON OARMS.CW_EVIDENCE_RULE_RELATION (RULE_ID);

-- 表注释
COMMENT ON TABLE OARMS.CW_EVIDENCE_RULE_RELATION IS '证据规则关联';

-- 列注释
COMMENT ON COLUMN OARMS.CW_EVIDENCE_RULE_RELATION.ID IS '主键ID';
COMMENT ON COLUMN OARMS.CW_EVIDENCE_RULE_RELATION.EVIDENCE_ID IS '证据ID';
COMMENT ON COLUMN OARMS.CW_EVIDENCE_RULE_RELATION.RULE_ID IS '监测规则ID';
COMMENT ON COLUMN OARMS.CW_EVIDENCE_RULE_RELATION.ASSOCIATED_BY IS '关联操作人';
COMMENT ON COLUMN OARMS.CW_EVIDENCE_RULE_RELATION.ASSOCIATED_AT IS '关联时间';
