CREATE SCHEMA DFXCONSOLE;

CREATE TABLE TB_CODE (
    CODE_GROUP VARCHAR(64) NOT NULL
    , CODE_NAME VARCHAR(64) NOT NULL
    , CODE_VALUE VARCHAR(1024) NOT NULL
    , CODE_DESCRIPTION VARCHAR(1024)
    , ORDER_NO DECIMAL(5) NOT NULL
    , PARENT_CODE_NAME VARCHAR(64)
    , USE_YN VARCHAR(1) NOT NULL
    , CONSTRAINT PK_CODE PRIMARY KEY (CODE_GROUP, CODE_NAME)
);

CREATE TABLE TB_DFX_USER (
    USER_UUID VARCHAR(64) NOT NULL
    , USER_EMAIL VARCHAR(320) NOT NULL
    , USER_PASSWORD VARCHAR(512)
    , USER_NICK VARCHAR(512) NOT NULL
    , USER_REGISTER_TIME VARCHAR(64)
    , LAST_LOGIN_TIME VARCHAR(64)
    , CONSTRAINT PK_DFX_USER PRIMARY KEY (USER_UUID)
);
COMMENT ON TABLE TB_DFX_USER IS 'DFXCONSOLE 사용자';
COMMENT ON COLUMN TB_DFX_USER.USER_UUID IS '사용자 UUID - 자동생성됨';
COMMENT ON COLUMN TB_DFX_USER.USER_EMAIL IS '사용자 email - 로그인 아이디로 사용됨';
COMMENT ON COLUMN TB_DFX_USER.USER_PASSWORD IS '사용자 비밀번호';
COMMENT ON COLUMN TB_DFX_USER.USER_NICK IS '닉네임';
COMMENT ON COLUMN TB_DFX_USER.USER_REGISTER_TIME IS '가입일시';
COMMENT ON COLUMN TB_DFX_USER.LAST_LOGIN_TIME IS '마지막 로그인 일시';
CREATE UNIQUE INDEX IX_DFX_USER_01 ON TB_DFX_USER(USER_EMAIL);

CREATE TABLE TB_DFX_AGENT_CONFIG (
    AGENT_ID VARCHAR(256) NOT NULL
    , HOST_NAME VARCHAR(256)
    , LISTEN_PORT DECIMAL(5) NOT NULL
    , DESCRIPTION VARCHAR(2048)
    , POSTMAN_COUNT DECIMAL(9)
    , DROPBOX_COUNT DECIMAL(9)
    , STATUS_CODE VARCHAR(64) NOT NULL
    , LAST_STATUS_TS TIMESTAMP NOT NULL
    , SETTINGS_DATA CLOB
    , CONSTRAINT PK_DFX_AGENT_CONFIG PRIMARY KEY (AGENT_ID)
);
COMMENT ON TABLE TB_DFX_AGENT_CONFIG IS '에이전트 설정';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.AGENT_ID IS '에이전트ID';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.HOST_NAME IS '에이전트가 설치된 HOSTNAME 또는 IP';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.LISTEN_PORT IS '에이전트 수신 포트';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.DESCRIPTION IS '에이전트 설명';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.POSTMAN_COUNT IS 'POSTMAN 갯수';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.DROPBOX_COUNT IS 'DROPBOX 갯수';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.STATUS_CODE IS '상태코드 CODE_GROUP: AGENT_STATUS_CODE';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.LAST_STATUS_TS IS '최종상태확인 시간';
COMMENT ON COLUMN TB_DFX_AGENT_CONFIG.SETTINGS_DATA IS '에이전스 설정 파일 내용';

