
DROP TABLE IF EXISTS tw_board_config;
CREATE TABLE tw_board_config (
    uid varchar(36) NOT NULL,
    name varchar(255) NOT NULL COMMENT '게시판명',
    isaccess varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '접근권한',
    isread varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '읽기권한',
    iswrite varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '쓰기권한',
    isreply varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT '답글권한',
    isupload varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT 'Upload권한',
    isdownload varchar(255) NOT NULL DEFAULT 'manager|cloudflare|director|master' COMMENT 'Download권한',
    head text NOT NULL DEFAULT '&nbsp;' COMMENT '게시판 위 내용',
    tail text NOT NULL DEFAULT '&nbsp;' 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)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 설정정보';

DROP TABLE IF EXISTS tw_board;
-- 1. 게시물 추가전 grpno에 해당하는 기존게시물의 grpord를 +1씩증가 작업
-- update tw_board set grporder=grporder+1 where grpno=그룹번호 and grporder > 선택한 grpno
-- 2. 게시물 추가시 작업
-- insert tw_board grpno=그룹번호,grporder=grporder+1,grpdepth=grpdepth+1
-- 3. 게시물 조회시 작업
-- select * from tw_board order by grpno desc,grporder asc
CREATE TABLE tw_board (
    uid int(10) unsigned NOT NULL AUTO_INCREMENT,
    grpno int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group번호: 상위가없을시 기본 uid와 같음',
    grporder int(5) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group순서: 상위가없을시 0부터시작',
    grpdepth int(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Group깊이: 상위가없을시 1부터시작 , 상위 grpdpt+1씩 추가필요',
	board_category_uid varchar(36) NOT NULL COMMENT '게시판구분',
    user_uid varchar(36) NULL COMMENT '작성자 정보',
    title varchar(255) NOT NULL COMMENT '제목',
    content text NOT NULL COMMENT '내용',
	passwd varchar(20) NULL COMMENT '작성자 암호',
	view_cnt int(5) NOT NULL DEFAULT 0 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 (board_category_uid) REFERENCES tw_board_config (uid),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 정보';

CREATE TABLE tw_board_file (
    uid int(10) unsigned NOT NULL AUTO_INCREMENT,
	tw_board_uid int(10) unsigned NOT NULL COMMENT '게시판 정보',
    mime_type varchar(50) NOT NULL COMMENT 'Mime_Type',
    name varchar(255) NOT NULL COMMENT '파일명',
    real_name varchar(255) NOT NULL 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 (tw_board_uid) REFERENCES tw_board (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='게시판 File정보';