
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),
    UNIQUE KEY (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_sns;

CREATE TABLE tw_user_sns (
    uid int(10) unsigned NOT NULL AUTO_INCREMENT,
    user_uid varchar(36) NULL COMMENT '사용자 정보',
    site varchar(20) NOT NULL COMMENT 'Site: GOOGLE,FACEBOOK 등등',
    id varchar(255) NOT NULL COMMENT 'sns 로그인 인중후 Return ID값',
    name varchar(50) NOT NULL,
    email 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),
    UNIQUE KEY (site,id),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='SNS 로그인 후 정보';

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