
DROP TABLE IF EXISTS tw_user;

CREATE TABLE tw_user (
    uid varchar(36) NOT NULL COMMENT "사용자 UUID",
    id varchar(30) NOT NULL,
    passwd varchar(100) NOT NULL,
    name varchar(20) NOT NULL COMMENT "사용자명",
    email varchar(50) NOT NULL,
    role varchar(30) NOT NULL DEFAULT 'user' COMMENT '사용자등급',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용,unuse: 사용않함',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid),
    UNIQUE KEY id (id),
    UNIQUE KEY email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='사용자 정보';
-- insert into tw_user (uid,id,passwd,name,email,role,status) select uuid(),id,passwd,name,email,role,status from cfmgr.user;
DROP TABLE IF EXISTS tw_user_profile;

CREATE TABLE tw_user_profile (
    uid int(10) unsigned NOT NULL AUTO_INCREMENT,
    user_uid varchar(36) NULL COMMENT '사용자 추가정보',
    type varchar(10) NOT NULL COMMENT 'ICON|ADDRESS|PHONE|MOBILE|EMAIL 등등',
    content varchar(255) NULL,
    priority int(3) NOT NULL DEFAULT 1 COMMENT '표시 우선순서',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용,unuse: 사용않함',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='사용자 추가정보';

DROP TABLE IF EXISTS tw_user_auth_google;

CREATE TABLE tw_user_auth_google (
    uid varchar(36) NOT NULL,
    id varchar(255) NOT NULL COMMENT 'sns 로그인 인중후 Return ID값',
    email varchar(50) NOT NULL,
    name varchar(50) NOT NULL,
    detail text NOT NULL COMMENT 'JSON형식 원본값',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 사용,unuse: 사용않함',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='GOOGLE 로그인 후 정보';

DROP TABLE IF EXISTS tw_logger;

CREATE TABLE tw_logger (
    uid int(10) unsigned NOT NULL AUTO_INCREMENT,
    user_uid varchar(36) NULL COMMENT '사용자 정보',
    title varchar(255) NOT NULL COMMENT 'title',
    content text NOT NULL COMMENT '내용',
    status varchar(10) NOT NULL DEFAULT 'use',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid)
) ENGINE = MyISAM DEFAULT CHARSET = utf8 COLLATE=utf8_unicode_ci COMMENT = 'log 정보';

DROP TABLE IF EXISTS tw_hpilo;

CREATE TABLE
    tw_hpilo (
        uid int(10) unsigned NOT NULL AUTO_INCREMENT,
        customer varchar(100) NOT NULL COMMENT '고객정보',
        id varchar(20) NOT NULL DEFAULT 'Administrator' COMMENT 'API IP Address',
        passwd varchar(20) NOT NULL COMMENT 'Password',
        ip varchar(50) NOT NULL COMMENT 'API IP Address',
        port int(5) unsigned NOT NULL COMMENT 'API Port',
        model varchar(255) NOT NULL DEFAULT 'model' COMMENT 'model',
        processor varchar(255) NOT NULL DEFAULT 'none' COMMENT 'processor',
        memory int(4) unsigned NOT NULL DEFAULT '0' COMMENT 'memory',
        health varchar(10) NOT NULL DEFAULT 'OK' COMMENT 'All Device Health',
        power varchar(10) NOT NULL DEFAULT 'Off' COMMENT 'Power status',
        detail text NOT NULL DEFAULT '' COMMENT '상세내용',
        status varchar(10) NOT NULL DEFAULT 'use',
        updated_at timestamp NULL DEFAULT NULL,
        created_at timestamp NOT NULL DEFAULT current_timestamp(),
        PRIMARY KEY (uid),
        UNIQUE KEY hpilokey (ip,port)
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8 COLLATE = utf8_general_ci COMMENT = 'hpilo 정보';