-- =============================================
-- SEAL_CONTRACT_LAUNCH_FILE 建表脚本 (Oracle)
-- 自动整理生成，已合并历史patch字段
-- 执行方式: sqlplus developer/dev123@localhost/XEPDB1 @SEAL_CONTRACT_LAUNCH_FILE.sql
-- =============================================

WHENEVER SQLERROR EXIT SQL.SQLCODE;

BEGIN
    EXECUTE IMMEDIATE 'DROP SEQUENCE SEQ_SEAL_CONTRACT_LAUNCH_FILE';
EXCEPTION
    WHEN OTHERS THEN
        IF SQLCODE != -2289 THEN RAISE; END IF;
END;
/

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE SEAL_CONTRACT_LAUNCH_FILE CASCADE CONSTRAINTS';
EXCEPTION
    WHEN OTHERS THEN
        IF SQLCODE != -942 THEN RAISE; END IF;
END;
/

CREATE TABLE SEAL_CONTRACT_LAUNCH_FILE (
    ID NUMBER(19) NOT NULL,
    CONTRACT_ID NUMBER(19) NOT NULL,
    FILE_CATEGORY VARCHAR2(30 CHAR) NOT NULL,
    ARCHIVE_ELE_ID NUMBER(19),
    FILE_NAME VARCHAR2(255 CHAR) NOT NULL,
    FILE_PATH VARCHAR2(500 CHAR) NOT NULL,
    LEGAL_FILE_URL VARCHAR2(1000 CHAR),
    FILE_TYPE VARCHAR2(50 CHAR),
    FILE_SIZE NUMBER(19),
    SORT_ORDER NUMBER(10) DEFAULT 1,
    CREATE_BY VARCHAR2(64 CHAR),
    CREATE_TIME DATE DEFAULT SYSDATE,
    UPDATE_BY VARCHAR2(64 CHAR),
    UPDATE_TIME DATE DEFAULT SYSDATE,
    IS_DELETED VARCHAR2(2 CHAR) DEFAULT 'N',
    REMARK VARCHAR2(1000 CHAR),
    CONSTRAINT PK_SEAL_CONTRACT_LAUNCH_FILE PRIMARY KEY (ID)
);

COMMENT ON TABLE SEAL_CONTRACT_LAUNCH_FILE IS '合同附件表';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.ID IS '主键ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.CONTRACT_ID IS '合同主表ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.FILE_CATEGORY IS '文件分类：body/other/gist/signed/archive';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.ARCHIVE_ELE_ID IS '关联合同电子档案材料ID';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.FILE_NAME IS '文件名称';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.FILE_PATH IS '文件路径';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.LEGAL_FILE_URL IS '法务系统附件路径缓存';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.FILE_TYPE IS '文件类型';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.FILE_SIZE IS '文件大小';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.SORT_ORDER IS '排序号';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.CREATE_BY IS '创建人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.UPDATE_BY IS '更新人';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.UPDATE_TIME IS '更新时间';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.IS_DELETED IS '逻辑删除标记';
COMMENT ON COLUMN SEAL_CONTRACT_LAUNCH_FILE.REMARK IS '备注';

CREATE INDEX IDX_SC_FILE_CTID ON SEAL_CONTRACT_LAUNCH_FILE (CONTRACT_ID);
CREATE INDEX IDX_SC_FILE_ARELE ON SEAL_CONTRACT_LAUNCH_FILE (ARCHIVE_ELE_ID);

CREATE SEQUENCE SEQ_SEAL_CONTRACT_LAUNCH_FILE
    INCREMENT BY 1
    MINVALUE 1
    MAXVALUE 9999999999999999999999999999
    NOCYCLE
    CACHE 20
    NOORDER;

COMMIT;
