DROP TABLE IF EXISTS user;

CREATE TABLE user (
    uid int(5) unsigned NOT NULL AUTO_INCREMENT,
    id varchar(20) NOT NULL,
    passwd varchar(30) NOT NULL,
    name varchar(20) NOT NULL,
    email varchar(50) NOT NULL,
    role varchar(10) NOT NULL DEFAULT 'user',
    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 id (id),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT ='사용자 정보';

DROP TABLE IF EXISTS user_sns;

CREATE TABLE user_sns (
    uid varchar(255) NOT NULL,
    user_uid int(5) unsigned NULL COMMENT 'user_uid',
    site varchar(50) NOT NULL,
    name varchar(20) NOT NULL,
    email varchar(50) NOT NULL,
    updated_at timestamp NULL DEFAULT NULL,
    status varchar(10) NOT NULL DEFAULT 'use',
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid),
    CONSTRAINT user_sns_ibfk_1 FOREIGN KEY (user_uid) REFERENCES user (uid) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT ='SNS 사용자 정보';

DROP TABLE IF EXISTS logger;

CREATE TABLE
    logger (
        uid int(5) unsigned NOT NULL AUTO_INCREMENT,
        user_uid int(5) unsigned NOT NULL COMMENT 'user_uid',
        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),
        CONSTRAINT logger_ibfk_1 FOREIGN KEY (user_uid) REFERENCES user (uid) ON DELETE CASCADE
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8 COMMENT = 'log 정보';

DROP TABLE IF EXISTS hpilo;

CREATE TABLE
    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 정보';
