create table DVPOWN.PT_USER
(
    ESNTL_ID                  VARCHAR2(36)  not null
        constraint PT_USER_PK
            primary key,
    USER_ID                   VARCHAR2(256) not null,
    USER_NAME                   VARCHAR2(60)  not null,
    PASSWORD                  VARCHAR2(200) not null,
    PASSWORD_HINT             VARCHAR2(100),
    PASSWORD_CNSR             VARCHAR2(100),
    MBTLNUM                   VARCHAR2(20),
    EMPLYR_STTUS_CODE         VARCHAR2(15)  not null,
    LOCK_AT                   CHAR,
    LOCK_CNT                  NUMBER(3),
    LAST_LOCK_DATE            TIMESTAMP(6),
    LAST_CHANGE_PASSWORD_DATE TIMESTAMP(6),
    REGISTERED_ON             TIMESTAMP(6),
    REGISTERED_BY             VARCHAR2(36),
    LAST_MODIFIED_ON          TIMESTAMP(6),
    LAST_MODIFIED_BY          VARCHAR2(36)
)
;

create unique index DVPOWN.PT_USER_UNIQUE_IDX
    on DVPOWN.PT_USER (USER_ID)
;

create table DVPOWN.PT_USER_AUD
(
    ESNTL_ID                  VARCHAR2(36)  not null,
    REV                       NUMBER(10)    not null,
    USER_ID                   VARCHAR2(256) not null,
    USER_NAME                   VARCHAR2(60),
    PASSWORD                  VARCHAR2(200),
    PASSWORD_HINT             VARCHAR2(100),
    PASSWORD_CNSR             VARCHAR2(100),
    MBTLNUM                   VARCHAR2(20),
    EMPLYR_STTUS_CODE         VARCHAR2(15),
    LOCK_AT                   CHAR,
    LOCK_CNT                  NUMBER(3),
    LAST_LOCK_DATE            TIMESTAMP(6),
    LAST_CHANGE_PASSWORD_DATE TIMESTAMP(6),
    REGISTERED_ON             TIMESTAMP(6),
    REGISTERED_BY             VARCHAR2(36),
    LAST_MODIFIED_ON          TIMESTAMP(6),
    LAST_MODIFIED_BY          VARCHAR2(36),
    REVTYPE                   NUMBER(3),
    constraint PT_USER_AUD_PK
        primary key (ESNTL_ID, REV)
)
;

create table DVPOWN.PT_ENT_USER
(
    ESNTL_ID                  VARCHAR2(36)  not null
        constraint PT_ENT_USER_PK
            primary key,
    USER_ID                   VARCHAR2(256) not null
        constraint PT_ENT_USER_UNIQUE_IDX
            unique,
    USER_NAME                   VARCHAR2(50)  not null,
    PASSWORD                  VARCHAR2(200) not null,
    STATUS                    VARCHAR2(15),
    MOBILE_PHONE              VARCHAR2(20),
    OFFICE_PHONE              VARCHAR2(20),
    COMPANY_NAME                VARCHAR2(60),
    CEO_NAME                  VARCHAR2(50),
    BIZRNO                    VARCHAR2(10),
    JURIRNO                   VARCHAR2(13),
    ZIP                       VARCHAR2(6),
    ADRES                     VARCHAR2(100),
    DETAIL_ADRES              VARCHAR2(100),
    FXNUM                     VARCHAR2(20),
    ENTRPRS_SE_CODE           CHAR(8),
    INDUTY_CODE               CHAR,
    PASSWORD_HINT             VARCHAR2(100),
    PASSWORD_CNSR             VARCHAR2(100),
    LOCK_AT                   CHAR,
    LOCK_CNT                  NUMBER(3),
    LAST_LOCK_DATE            TIMESTAMP(6),
    LAST_CHANGE_PASSWORD_DATE TIMESTAMP(6),
    REGISTERED_ON             TIMESTAMP(6),
    REGISTERED_BY             VARCHAR2(36),
    LAST_MODIFIED_ON          TIMESTAMP(6),
    LAST_MODIFIED_BY          VARCHAR2(36)
)
;

create table DVPOWN.PT_ENT_USER_AUD
(
    ESNTL_ID                  VARCHAR2(36) not null,
    REV                       NUMBER(10)   not null,
    USER_ID                   VARCHAR2(256),
    USER_NAME                   VARCHAR2(50),
    PASSWORD                  VARCHAR2(200),
    STATUS                    VARCHAR2(15),
    MOBILE_PHONE              VARCHAR2(20),
    OFFICE_PHONE              VARCHAR2(20),
    COMPANY_NAME                VARCHAR2(60),
    CEO_NAME                  VARCHAR2(50),
    BIZRNO                    VARCHAR2(10),
    JURIRNO                   VARCHAR2(13),
    ZIP                       VARCHAR2(6),
    ADRES                     VARCHAR2(100),
    DETAIL_ADRES              VARCHAR2(100),
    FXNUM                     VARCHAR2(20),
    ENTRPRS_SE_CODE           CHAR(8),
    INDUTY_CODE               CHAR,
    PASSWORD_HINT             VARCHAR2(100),
    PASSWORD_CNSR             VARCHAR2(100),
    LOCK_AT                   CHAR,
    LOCK_CNT                  NUMBER(3),
    LAST_LOCK_DATE            TIMESTAMP(6),
    LAST_CHANGE_PASSWORD_DATE TIMESTAMP(6),
    REGISTERED_ON             TIMESTAMP(6),
    REGISTERED_BY             VARCHAR2(36),
    LAST_MODIFIED_ON          TIMESTAMP(6),
    LAST_MODIFIED_BY          VARCHAR2(36),
    REVTYPE                   NUMBER(3)    not null,
    primary key (ESNTL_ID, REV)
)
;

create table DVPOWN.PT_APPROVAL
(
    ID               NUMBER(19) not null,
    APPROVAL_TYPE    VARCHAR2(32),
    BODY             CLOB,
    ENDED_ON         TIMESTAMP(6),
    REQUESTER_ID     VARCHAR2(36),
    STATUS           VARCHAR2(32),
    TARGET_ID        VARCHAR2(36),
    TITLE            VARCHAR2(255),
    REGISTERED_BY    VARCHAR2(36),
    REGISTERED_ON    TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    primary key (ID)
)
;

create table DVPOWN.PT_APPROVAL_APPROVER
(
    APPROVAL_ID NUMBER(19) not null
        constraint FK_APPROVAL_APPROVER
            references DVPOWN.PT_APPROVAL,
    ORDINAL     NUMBER(19) not null,
    APPROVED_ON TIMESTAMP(6),
    MESSAGE     VARCHAR2(255),
    STATUS      VARCHAR2(255),
    USER_ID     VARCHAR2(36),
    primary key (APPROVAL_ID, ORDINAL)
)
;

create table DVPOWN.PT_ROUTE_INFO
(
    ID                    VARCHAR2(36)  not null,
    API_PATH              VARCHAR2(512),
    DESCRIPTION           CLOB,
    LOG_CONTENT_ENCODE_YN VARCHAR2(1),
    LOG_LEVEL             VARCHAR2(1),
    NAME                  VARCHAR2(256) not null,
    ORDER_NO              NUMBER(10),
    PATH                  VARCHAR2(256) not null,
    METHOD                VARCHAR2(32),
    META_DATA_STR         CLOB,
    RESPONSE_TYPE         VARCHAR2(32) NULL,
    SAMPLE_RESPONSE       CLOB,
    STATUS                VARCHAR2(32),
    TYPE                  VARCHAR2(2),
    URI                   VARCHAR2(512) not null,
    USE_YN                VARCHAR2(1),
    FILE_ID               VARCHAR2(20),
    REGISTERED_BY         VARCHAR2(36),
    REGISTERED_ON         TIMESTAMP(6),
    LAST_MODIFIED_BY      VARCHAR2(36),
    LAST_MODIFIED_ON      TIMESTAMP(6),
    primary key (ID)
)
;

create table DVPOWN.PT_API_KEY
(
    ID               VARCHAR2(36) not null,
    OWNER            VARCHAR2(255),
    NAME             VARCHAR2(255),
    ENV              VARCHAR2(32),
    CLIENT_ID        VARCHAR2(255),
    CLIENT_SECRET    VARCHAR2(255),
    REDIRECT_URL     VARCHAR2(255),
    RESPONSE_TYPE    VARCHAR2(255),
    SCOPE            VARCHAR2(2000),
    STATUS           VARCHAR2(255),
    DESCRIPTION      VARCHAR2(2000),
    REGISTERED_BY    VARCHAR2(36),
    REGISTERED_ON    TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    primary key (ID)
)
;

create table DVPOWN.PT_API_KEY_API
(
    API_KEY_ID VARCHAR2(36) not null
        constraint FK_API_KEY_API1
            references DVPOWN.PT_API_KEY,
    API_ID     VARCHAR2(36) not null
        constraint FK_API_KEY_API2
            references DVPOWN.PT_ROUTE_INFO
)
;

create table DVPOWN.PT_AGREEMENTS
(
    AGREEMENTS_TYPE     VARCHAR2(20)  not null,
    REVISION            NUMBER(10)    not null,
    AGREEMENTS_NAME     VARCHAR2(100) not null,
    AGREEMENTS_CONTENTS CLOB,
    STATUS              VARCHAR2(20),
    PUBLISHED_ON        TIMESTAMP(6),
    SCHEDULED_ON        TIMESTAMP(6),
    REGISTERED_BY       VARCHAR2(36),
    REGISTERED_ON       TIMESTAMP(6),
    LAST_MODIFIED_BY    VARCHAR2(36),
    LAST_MODIFIED_ON    TIMESTAMP(6),
    primary key (AGREEMENTS_TYPE, REVISION)
)
;

create table DVPOWN.PT_MESSAGE_TEMPLATE
(
    MESSAGE_KEY      VARCHAR2(32)  not null,
    MESSAGE_TYPE     VARCHAR2(16)  not null,
    SUBJECT          VARCHAR2(100) not null,
    CONTENTS         CLOB,
    USE_YN           VARCHAR2(1),
    REGISTERED_BY    VARCHAR2(36),
    REGISTERED_ON    TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    primary key (MESSAGE_KEY, MESSAGE_TYPE)
)
;


CREATE TABLE DVPOWN.PT_MESSAGE_RECIPIENT
(
    MESSAGE_KEY  VARCHAR2(32) not null,
    MESSAGE_TYPE VARCHAR2(16) not null,
    ESNTL_ID     VARCHAR2(36) not null,
    constraint PK_MESSAGE_RECIPIENT PRIMARY KEY (MESSAGE_KEY, MESSAGE_TYPE, ESNTL_ID)
)
;

create table PT_TOKEN
(
(
    TOKEN      VARCHAR2(255) not null
        primary key,
    EMAIL      VARCHAR2(255) not null,
    EXPIRES_AT TIMESTAMP(6)  not null
)
;

create table DVPOWN.PT_BOARD_AUTHORITY
(
    AUTHORITY_ID     VARCHAR2(20) not null
        primary key,
    BBS_ID           VARCHAR2(20) not null,
    AUTHORITY_CODE   VARCHAR2(36),
    ESNTL_ID         VARCHAR2(36),
    READ_YN          VARCHAR2(1)  not null,
    WRITE_YN         VARCHAR2(1)  not null,
    MODIFY_YN        VARCHAR2(1)  not null,
    DELETE_YN        VARCHAR2(1)  not null,
    ADMIN_YN         VARCHAR2(1)  not null,
    REGISTERED_BY    VARCHAR2(36),
    REGISTERED_ON    TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6)
)
;

create table DVPOWN.COMTECOPSEQ
(
    TABLE_NAME VARCHAR2(20) not null
        constraint COMTECOPSEQ_PK
            primary key,
    NEXT_ID    NUMBER(30)
)
;

create table DVPOWN.COMTCCMMNCODE
(
    CODE_ID          VARCHAR2(6) not null
        constraint COMTCCMMNCODE_PK
            primary key,
    CODE_ID_NAME       VARCHAR2(60),
    CODE_ID_DC       VARCHAR2(200),
    USE_AT           CHAR,
    CL_CODE          CHAR(3),
    REGISTERED_ON    TIMESTAMP(6),
    REGISTERED_BY    VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36)
)
;

create index DVPOWN.COMTCCMMNCODE_I01
    on DVPOWN.COMTCCMMNCODE (CL_CODE)
;

create table DVPOWN.COMTCCMMNDETAILCODE
(
    CODE_ID          VARCHAR2(6)  not null
        constraint COMTCCMMNDETAILCODE_FK1
            references DVPOWN.COMTCCMMNCODE,
    CODE             VARCHAR2(15) not null,
    CODE_VALUE          VARCHAR2(4000) not null,
    CODE_DC          VARCHAR2(200),
    USE_AT           CHAR,
    REGISTERED_ON    TIMESTAMP(6),
    REGISTERED_BY    VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    constraint COMTCCMMNDETAILCODE_PK
        primary key (CODE_ID, CODE)
)
;

create index DVPOWN.COMTCCMMNDETAILCODE_I01
    on DVPOWN.COMTCCMMNDETAILCODE (CODE_ID)
;

create table DVPOWN.COMTNAUTHORINFO
(
    AUTHOR_CODE     VARCHAR2(30) not null
        constraint COMTNAUTHORINFO_PK
            primary key,
    AUTHOR_NAME       VARCHAR2(60) not null,
    AUTHOR_DC       VARCHAR2(200),
    AUTHOR_CREAT_DE TIMESTAMP(6)
)
;

create table DVPOWN.COMTNEMPLYRSCRTYESTBS
(
    SCRTY_DTRMN_TRGET_ID VARCHAR2(36) not null,
    MBER_TY_CODE         CHAR(5),
    AUTHOR_CODE          VARCHAR2(30) not null
)
;

create index DVPOWN.COMTNEMPLYRSCRTYESTBS_I04
    on DVPOWN.COMTNEMPLYRSCRTYESTBS (AUTHOR_CODE)
;

create table DVPOWN.COMTNBBSMASTER
(
    BBS_ID                 CHAR(20)      not null
        constraint COMTNBBSMASTER_PK
            primary key,
    BBS_NAME                 VARCHAR2(255) not null,
    BBS_INTRCN             VARCHAR2(2400),
    BBS_TY_CODE            CHAR(6)       not null,
    REPLY_POSBL_AT         CHAR,
    FILE_ATCH_POSBL_AT     CHAR          not null,
    ATCH_POSBL_FILE_NUMBER NUMBER(2)     not null,
    ATCH_POSBL_FILE_SIZE   NUMBER(8),
    USE_AT                 CHAR          not null,
    TMPLAT_ID              CHAR(20),
    CMMNTY_ID              CHAR(20),
    REGISTERED_BY          VARCHAR2(36),
    REGISTERED_ON          TIMESTAMP(6),
    LAST_MODIFIED_BY       VARCHAR2(36),
    LAST_MODIFIED_ON       TIMESTAMP(6),
    BLOG_ID                CHAR(20),
    BLOG_AT                CHAR(2)
)
;

create table DVPOWN.COMTNFILE
(
    ATCH_FILE_ID CHAR(20)     not null
        constraint COMTNFILE_PK
            primary key,
    CREAT_DT     TIMESTAMP(6) not null,
    USE_AT       CHAR
)
;

create table DVPOWN.COMTNFILEDETAIL
(
    ATCH_FILE_ID   CHAR(20)   not null
        constraint COMTNFILEDETAIL_FK1
            references DVPOWN.COMTNFILE,
    FILE_SN        NUMBER(10) not null,
    ORIGNL_FILE_NAME VARCHAR2(255),
    FILE_EXTSN     VARCHAR2(20),
    FILE_CN        CLOB,
    FILE_SIZE      NUMBER(8),
    constraint COMTNFILEDETAIL_PK
        primary key (ATCH_FILE_ID, FILE_SN)
)
;

create index DVPOWN.COMTNFILEDETAIL_I01
    on DVPOWN.COMTNFILEDETAIL (ATCH_FILE_ID)
;

create table DVPOWN.COMTNBBS
(
    NTT_ID           NUMBER(20) not null,
    BBS_ID           CHAR(20)   not null
        constraint COMTNBBS_FK1
            references DVPOWN.COMTNBBSMASTER,
    NTT_NO           NUMBER(20),
    NTT_SJ           VARCHAR2(2000),
    NTT_CN           CLOB,
    ANSWER_AT        CHAR,
    PARNTSCTT_NO     NUMBER(10),
    ANSWER_LC        NUMBER(8),
    SORT_ORDR        NUMBER(8),
    RDCNT            NUMBER(10),
    USE_AT           CHAR       not null,
    NTCE_BGNDE       CHAR(20),
    NTCE_ENDDE       CHAR(20),
    NTCR_ID          VARCHAR2(36),
    NTCR_NAME          VARCHAR2(20),
    PASSWORD         VARCHAR2(200),
    ATCH_FILE_ID     CHAR(20)
        constraint COMTNBBS_FK2
            references DVPOWN.COMTNFILE,
    NOTICE_AT        CHAR,
    SJ_BOLD_AT       CHAR,
    SECRET_AT        CHAR,
    REGISTERED_ON    TIMESTAMP(6),
    REGISTERED_BY    VARCHAR2(36),
    LAST_MODIFIED_ON TIMESTAMP(6),
    LAST_MODIFIED_BY VARCHAR2(36),
    BLOG_ID          CHAR(20),
    constraint COMTNBBS_PK
        primary key (NTT_ID, BBS_ID)
)
;

create index DVPOWN.COMTNBBS_I01
    on DVPOWN.COMTNBBS (BBS_ID)
;

create table DVPOWN.COMTNFAQINFO
(
    FAQ_ID                 CHAR(20) not null
        constraint COMTNFAQINFO_PK
            primary key,
    QESTN_SJ               VARCHAR2(255),
    QESTN_CN               VARCHAR2(2500),
    ANSWER_CN              VARCHAR2(2500),
    RDCNT                  NUMBER(10),
    REGISTERED_ON          TIMESTAMP(6),
    REGISTERED_BY          VARCHAR2(36),
    LAST_MODIFIED_ON       TIMESTAMP(6),
    LAST_MODIFIED_BY       VARCHAR2(36),
    ATCH_FILE_ID           CHAR(20)
        constraint COMTNFAQINFO_FK1
            references DVPOWN.COMTNFILE
                on delete set null,
    QNA_PROCESS_STTUS_CODE CHAR
)
;

create index DVPOWN.COMTNFAQINFO_I01
    on DVPOWN.COMTNFAQINFO (ATCH_FILE_ID)
;

create table DVPOWN.PT_TWO_FACTOR_AUTH
(
    RECIPIENT   VARCHAR2(255) not null
        primary key,
    AUTH_NUMBER VARCHAR2(255),
    EXPIRES_AT  TIMESTAMP(6)
)
;

CREATE table DVPOWN.REVINFO
(
    REVTSTMP NUMBER,
    REV      NUMBER
)
;



CREATE SEQUENCE DVPOWN.HIBERNATE_SEQUENCE;


CREATE VIEW DVPOWN.COMVNUSERMASTER
    (ESNTL_ID, USER_ID, PASSWORD, USER_NAME, GROUP_ID, USER_SE, ORGNZT_ID)
AS
SELECT ESNTL_ID,
       USER_ID,
       PASSWORD,
       USER_NAME,
       GROUP_ID,
       'USR' AS USER_SE,
       ORGNZT_ID
FROM PT_USER
UNION ALL
SELECT ESNTL_ID,
       USER_ID,
       PASSWORD,
       USER_NAME,
       ' ',
       'ENT' AS USER_SE,
       ' '      ORGNZT_ID
FROM PT_ENT_USER
ORDER BY ESNTL_ID;