INSERT INTO `system_role` (`id`, `name`, `role_type`, `register_id`, `register_date`, `modify_id`, `modify_date`) VALUES
(3, '프로젝트 사용자 역할', '03', 1, '2017-12-29 21:37:15', 1, '2017-12-29 21:37:15'),
(4, '프로젝트 관리자 역할', '04', 1, '2017-12-29 21:37:15', 1, '2017-12-29 21:37:15');

DELETE FROM `system_role_permission` WHERE id = '5';
DELETE FROM `system_role_permission` WHERE id = '6';
DELETE FROM `system_role_permission` WHERE id = '7';
DELETE FROM `system_role_permission` WHERE id = '8';

CREATE TABLE `workflow_status` (
   `id` INT(11) NOT NULL AUTO_INCREMENT,
   `project_id` BIGINT(20) NULL,
   `name` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8_general_ci',
   `first_yn` VARCHAR(1) NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
   `last_yn` VARCHAR(1) NOT NULL DEFAULT 'N' COLLATE 'utf8_general_ci',
   `progress` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '진행률',
   `color` VARCHAR(255) NOT NULL DEFAULT '0' COLLATE 'utf8_general_ci',
   `position` BIGINT(20) NOT NULL DEFAULT '0',
   `register_id` BIGINT(20) NOT NULL COMMENT 'register_id',
   `register_date` TIMESTAMP NULL COMMENT 'register_date',
   `modify_id` BIGINT(20) NOT NULL COMMENT 'modify_id',
   `modify_date` TIMESTAMP NULL COMMENT 'modify_date',
   PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `user` ADD COLUMN `last_project_id` bigint(20) NULL DEFAULT '0';
ALTER TABLE `user` ADD COLUMN `last_login_date` TIMESTAMP NULL;
ALTER TABLE `issue` ADD COLUMN `workflow_status_id` bigint(20) NULL DEFAULT NULL;

/* 프로젝트 클로저 테이블 */
CREATE TABLE `project_closure` (
   `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `project_id` BIGINT(20) NOT NULL,
   `parent_project_id` BIGINT(20) NOT NULL DEFAULT -1,
   `register_id` BIGINT(20) NOT NULL COMMENT 'register_id',
   `register_date` TIMESTAMP NULL COMMENT 'register_date',
   `modify_id` BIGINT(20) NOT NULL COMMENT 'modify_id',
   `modify_date` TIMESTAMP NULL COMMENT 'modify_date',
   PRIMARY KEY (`id`) USING BTREE,
   INDEX `projectIdIndex` (`project_id`) USING BTREE,
   INDEX `parentProjectIdIndex` (`parent_project_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

/* 연관 이슈 테이블 */
CREATE TABLE `issue_relation` (
   `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
   `issue_id` BIGINT(20) NOT NULL,
   `relation_issue_id` BIGINT(20) NOT NULL DEFAULT -1,
   `relation_issue_type` INT(20) NOT NULL,
   `register_id` BIGINT(20) NOT NULL COMMENT 'register_id',
   `register_date` TIMESTAMP NULL COMMENT 'register_date',
   `modify_id` BIGINT(20) NOT NULL COMMENT 'modify_id',
   `modify_date` TIMESTAMP NULL COMMENT 'modify_date',
   PRIMARY KEY (`id`) USING BTREE,
   INDEX `issueId` (`issue_id`) USING BTREE,
   INDEX `relationIssueId` (`relation_issue_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

/* 유저 로그인 이력 테이블 (히스토리 불필요) */
-- CREATE TABLE `user_history` (
--    `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
--    `history_type` VARCHAR (20) NOT NULL,
--    `register_id` BIGINT(20) NOT NULL COMMENT 'register_id',
--    `register_date` TIMESTAMP NULL COMMENT 'register_date',
--    `modify_id` BIGINT(20) NOT NULL COMMENT 'modify_id',
--    `modify_date` TIMESTAMP NULL COMMENT 'modify_date',
--    PRIMARY KEY (`id`) USING BTREE
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `custom_field` ADD COLUMN `use_flag` varchar(1) NOT NULL DEFAULT 'Y';