DELETE FROM `zt_block` WHERE `type` IN ('news', 'patch', 'plugin', 'puglicclass');

ALTER TABLE `zt_block` ADD `dashboard` varchar(20) NOT NULL DEFAULT '' AFTER `account`;
ALTER TABLE `zt_block` CHANGE `block` `code` varchar(30) NOT NULL DEFAULT '' AFTER `module`;
ALTER TABLE `zt_block` ADD `width` enum ('1', '2', '3') NOT NULL DEFAULT '1' AFTER `code`;
ALTER TABLE `zt_block` MODIFY `height` smallint(5) UNSIGNED NOT NULL DEFAULT 3 AFTER `width`;
ALTER TABLE `zt_block` ADD `left` enum('0', '1', '2') NOT NULL DEFAULT '0' AFTER `height`;
ALTER TABLE `zt_block` ADD `top` smallint(5) UNSIGNED NOT NULL DEFAULT 0 AFTER `left`;
ALTER TABLE `zt_block` MODIFY `vision` varchar(10) NOT NULL DEFAULT 'rnd' AFTER `hidden`;

DROP INDEX account_vision_module_type_order ON `zt_block`;
UPDATE `zt_block` SET `dashboard` = CONCAT(`module`, `type`);
UPDATE `zt_block` SET `module` = IF(`source` != '', `source`, `code`);
UPDATE `zt_block` SET `width` = IF(`grid` > 4, '2', '1');
UPDATE `zt_block` SET `params` = '{"count":"20"}' WHERE `module` = 'assigntome' AND `code` = 'assigntome';

ALTER TABLE `zt_block` DROP COLUMN `source`;
ALTER TABLE `zt_block` DROP COLUMN `type`;
ALTER TABLE `zt_block` DROP COLUMN `grid`;
ALTER TABLE `zt_block` DROP COLUMN `order`;

DELETE FROM `zt_block` where `module` = 'todo' and `code` = 'list';
DELETE FROM `zt_block` where `module` = 'contribute' and `code` = 'contribute';
DELETE FROM `zt_block` where `module` = 'project' and `code` = 'projectteam';

ALTER TABLE `zt_todo`  CHANGE `idvalue` `objectID` mediumint(8) unsigned default '0' NOT NULL AFTER `type`;
ALTER TABLE `zt_todo` CHANGE `config` `config` VARCHAR(1000) NOT NULL  DEFAULT '';

ALTER TABLE `zt_project` ADD `stageBy` enum('project', 'product') NOT NULL DEFAULT 'product' AFTER `division`;
UPDATE `zt_project` SET `stageBy` = 'project' WHERE `division` = '0';
UPDATE `zt_project` SET `stageBy` = 'product' WHERE `division` = '1';
ALTER TABLE `zt_project` DROP `division`;

ALTER TABLE `zt_bug` CHANGE `linkBug` `relatedBug` varchar(255) NOT NULL DEFAULT '';

ALTER TABLE `zt_product` ADD COLUMN `groups` text NULL AFTER `acl`;

ALTER TABLE `zt_usercontact` ADD `public` tinyint(1) NOT NULL DEFAULT 0;
UPDATE `zt_usercontact` AS t1, `zt_config` AS t2 SET t1.public = 1 WHERE t2.module = 'my' AND t2.section = 'global' AND t2.key = 'globalContacts' AND FIND_IN_SET(t1.id, t2.value); -- Change it for compatible with dameng.
DELETE FROM `zt_config` WHERE `module` = 'my' AND `section` = 'global' AND `key` = 'globalContacts';

ALTER TABLE `zt_testtask` ADD `realBegan` date NULL AFTER `end`;

UPDATE `zt_config` SET `module` = 'bug', `section` = 'browse' WHERE `module` = 'datatable' AND `section` = 'bugBrowse' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'caselib', `section` = 'browse' WHERE `module` = 'datatable' AND `section` = 'caselibBrowse' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'execution', `section` = 'bug' WHERE `module` = 'datatable' AND `section` = 'executionBug' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'execution', `section` = 'story' WHERE `module` = 'datatable' AND `section` = 'executionStory' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'execution', `section` = 'task' WHERE `module` = 'datatable' AND `section` = 'executionTask' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'feedback', `section` = 'admin' WHERE `module` = 'datatable' AND `section` = 'feedbackAdmin' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'product', `section` = 'browse' WHERE `module` = 'datatable' AND `section` = 'productBrowse' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'project', `section` = 'bug' WHERE `module` = 'datatable' AND `section` = 'projectBug' AND `key` = 'showModule';
UPDATE `zt_config` SET `module` = 'testcase', `section` = 'browse' WHERE `module` = 'datatable' AND `section` = 'testcaseBrowse' AND `key` = 'showModule';

INSERT IGNORE INTO `zt_config` (`owner`, `module`, `key`, `value`) VALUES ('system', 'execution', 'defaultWorkhours', '7');

CREATE TABLE IF NOT EXISTS `zt_session` (
    `id` varchar(32) NOT NULL,
    `data` mediumtext,
    `timestamp` int(10) unsigned DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `zt_action` MODIFY `id` int(11) unsigned NOT NULL AUTO_INCREMENT;
ALTER TABLE `zt_actionrecent` MODIFY `id` int(11) unsigned NOT NULL AUTO_INCREMENT;
ALTER TABLE `zt_mr` ADD executionID mediumint(8) unsigned NOT NULL DEFAULT 0 AFTER `jobID`;

ALTER TABLE `zt_testtask` ADD COLUMN `members` text NULL;
UPDATE `zt_solutions` SET `deleted` = '0' WHERE `deleted` = '';

/* Update createdBy to system in chart and pivot. */
UPDATE `zt_chart` SET `createdBy` = 'system' WHERE `builtin` = '1';
UPDATE `zt_pivot` SET `createdBy` = 'system' WHERE `id` >= 1000 and `id` <= 1027;

UPDATE `zt_chart` SET `type` = 'cluBarY', `settings` = '[{\"type\":\"cluBarY\",\"xaxis\":[{\"field\":\"topProgram\",\"name\":\"topProgram\",\"group\":\"\"}],\"yaxis\":[{\"field\":\"storyDoneRate\",\"name\":\"storyDoneRate\",\"valOrAgg\":\"sum\"},{\"field\":\"bugSolvedRate\",\"name\":\"bugSolvedRate\",\"valOrAgg\":\"sum\"}]}]', `fields` = '{\"topProgram\":{\"name\":\"topProgram\",\"object\":\"bug\",\"field\":\"topProgram\",\"type\":\"string\"},\"doneStory\":{\"name\":\"doneStory\",\"object\":\"bug\",\"field\":\"doneStory\",\"type\":\"number\"},\"allStory\":{\"name\":\"allStory\",\"object\":\"bug\",\"field\":\"allStory\",\"type\":\"number\"},\"storyDoneRate\":{\"name\":\"storyDoneRate\",\"object\":\"bug\",\"field\":\"storyDoneRate\",\"type\":\"number\"},\"solvedBug\":{\"name\":\"solvedBug\",\"object\":\"bug\",\"field\":\"solvedBug\",\"type\":\"number\"},\"allBug\":{\"name\":\"allBug\",\"object\":\"bug\",\"field\":\"allBug\",\"type\":\"number\"},\"bugSolvedRate\":{\"name\":\"bugSolvedRate\",\"object\":\"bug\",\"field\":\"bugSolvedRate\",\"type\":\"number\"}}', `langs` = '{\"topProgram\":{\"zh-cn\":\"\\u4e00\\u7ea7\\u9879\\u76ee\\u96c6\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"doneStory\":{\"zh-cn\":\"\\u5b8c\\u6210\\u9700\\u6c42\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"allStory\":{\"zh-cn\":\"\\u9700\\u6c42\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"storyDoneRate\":{\"zh-cn\":\"\\u9700\\u6c42\\u5b8c\\u6210\\u7387\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"solvedBug\":{\"zh-cn\":\"\\u89e3\\u51b3bug\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"allBug\":{\"zh-cn\":\"bug\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"bugSolvedRate\":{\"zh-cn\":\"bug\\u4fee\\u590d\\u7387\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"}}', `sql` = 'SELECT\n    t1.name AS topProgram,\n    SUM(IFNULL(t3.doneStory,0)) as doneStory,\n    SUM(IFNULL(t4.allStory,0)) as allStory,\n    CONVERT(IF(SUM(IFNULL(t4.allStory,0)) <= 0, 0, SUM(IFNULL(t3.doneStory,0)) / SUM(IFNULL(t4.allStory,0))*100), decimal(10,2)) as storyDoneRate,                                                                                                                                         \n    SUM(IFNULL(t5.solvedBug,0)) as solvedBug,\n    SUM(IFNULL(t6.allBug,0)) as allBug,\n    CONVERT(IF(SUM(IFNULL(t6.allBug,0)) <= 0, 0, SUM(IFNULL(t5.solvedBug,0)) / SUM(IFNULL(t6.allBug,0))*100), decimal(10,2)) as bugSolvedRate\nFROM zt_project AS t1\nLEFT JOIN zt_product AS t2 ON t1.id = t2.program\nLEFT JOIN (SELECT COUNT(1) as doneStory, product FROM zt_story WHERE deleted = \'0\' AND closedReason = \'done\' AND status = \'closed\' GROUP BY product) AS t3 ON t2.id = t3.product\nLEFT JOIN (SELECT COUNT(1) as allStory, product FROM zt_story WHERE deleted = \'0\' AND ((closedReason = \'done\' AND status = \'closed\') OR status != \'closed\') GROUP BY product) AS t4 ON t2.id = t4.product\nLEFT JOIN (SELECT COUNT(1) as solvedBug, product FROM zt_bug WHERE deleted = \'0\' AND resolution = \'fixed\' AND status = \'closed\' GROUP BY product) AS t5 ON t2.id = t5.product\nLEFT JOIN (SELECT COUNT(1) as allBug, product FROM zt_bug WHERE deleted = \'0\' AND (resolution in (\'fixed\', \'postponed\') OR status = \'active\') GROUP BY product) AS t6 ON t2.id = t6.product\nWHERE t1.type = \'program\' AND t1.grade = 1 AND t1.deleted = \'0\'\nAND t2.deleted = \'0\'\nGROUP BY t1.name\nORDER BY t1.`order` DESC', `stage` = 'published', `builtin` = 0 WHERE `id` = 1042;
UPDATE `zt_chart` SET `type` = 'pie',     `settings` = '[{\"type\":\"pie\",\"group\":[{\"field\":\"status\",\"name\":\"\\u72b6\\u6001\",\"group\":\"\"}],\"metric\":[{\"field\":\"id\",\"name\":\"\\u9879\\u76eeID\",\"valOrAgg\":\"count\"}]}]',                                                                                        `fields` = '{\"id\":{\"name\":\"\\u9879\\u76eeID\",\"object\":\"project\",\"field\":\"id\",\"type\":\"number\"},\"status\":{\"name\":\"\\u72b6\\u6001\",\"object\":\"project\",\"field\":\"status\",\"type\":\"option\"}}', `langs` = '', `sql` = 'SELECT id, CASE `status` WHEN \'wait\' then \'未开始\' WHEN \'doing\' THEN \'进行中\' WHEN \'suspended\' THEN \'已挂起\' ELSE \'已关闭\' END status FROM zt_project  WHERE type = \'program\' AND grade = 1 AND deleted = \'0\'', `stage` = 'published', `builtin` = 0 WHERE `id` = 1043;
UPDATE `zt_chart` SET `type` = 'pie',     `settings` = '[{\"type\":\"pie\",\"group\":[{\"field\":\"status\",\"name\":\"\\u72b6\\u6001\",\"group\":\"\"}],\"metric\":[{\"field\":\"id\",\"name\":\"\\u9879\\u76eeID\",\"valOrAgg\":\"count\"}]}]',                                                                                        `fields` = '{\"id\":{\"name\":\"\\u9879\\u76eeID\",\"object\":\"project\",\"field\":\"id\",\"type\":\"number\"},\"status\":{\"name\":\"\\u72b6\\u6001\",\"object\":\"project\",\"field\":\"status\",\"type\":\"option\"}}', `langs` = '', `sql` = 'SELECT id, CASE `status` WHEN \'wait\' then \'未开始\' WHEN \'doing\' THEN \'进行中\' WHEN \'suspended\' THEN \'已挂起\' ELSE \'已关闭\' END status FROM zt_project  WHERE type = \'project\' AND deleted = \'0\'', `stage` = 'published', `builtin` = 0 WHERE `id` = 1044;
UPDATE `zt_chart` SET `type` = 'cluBarY', `settings` = '[{\"type\":\"cluBarY\",\"xaxis\":[{\"field\":\"product\",\"name\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"group\":\"\"}],\"yaxis\":[{\"field\":\"closedRate\",\"name\":\"closedRate\",\"valOrAgg\":\"sum\"}]}]',                                                                      `fields` = '{\"product\":{\"name\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"object\":\"story\",\"field\":\"product\",\"type\":\"string\"},\"program\":{\"name\":\"program\",\"object\":\"story\",\"field\":\"program\",\"type\":\"string\"},\"productLine\":{\"name\":\"productLine\",\"object\":\"story\",\"field\":\"productLine\",\"type\":\"string\"},\"closedStory\":{\"name\":\"\\u9700\\u6c42\\uff1a%s \\u5df2\\u5173\\u95ed\\uff0c\\u5c06\\u4e0d\\u4f1a\\u88ab\\u5173\\u95ed\\u3002\",\"object\":\"story\",\"field\":\"closedStory\",\"type\":\"string\"},\"totalStory\":{\"name\":\"totalStory\",\"object\":\"story\",\"field\":\"totalStory\",\"type\":\"string\"},\"closedRate\":{\"name\":\"closedRate\",\"object\":\"story\",\"field\":\"closedRate\",\"type\":\"number\"}}', `langs` = '{\"product\":{\"zh-cn\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"program\":{\"zh-cn\":\"\\u9879\\u76ee\\u96c6\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"productLine\":{\"zh-cn\":\"\\u4ea7\\u54c1\\u7ebf\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"closedStory\":{\"zh-cn\":\"\\u5b8c\\u6210\\u9700\\u6c42\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"totalStory\":{\"zh-cn\":\"\\u9700\\u6c42\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"closedRate\":{\"zh-cn\":\"\\u9700\\u6c42\\u5b8c\\u6210\\u7387\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"}}', `sql` = 'SELECT\n  t1.name AS product,\n  IFNULL(t2.name, \'/\') AS program, \n  IFNULL(t3.name, \'/\') AS productLine,   \n  IFNULL(t4.story, 0) AS closedStory, \n  t5.story AS totalStory, \n  ROUND(IFNULL(t4.story, 0) / t5.story * 100, 2) AS closedRate \nFROM zt_product AS t1 \nLEFT JOIN zt_project AS t2 ON t1.program = t2.id AND t2.type = \'program\' AND t2.grade = 1 \nLEFT JOIN zt_module AS t3 ON t1.line = t3.id AND t3.type = \'line\' \nLEFT JOIN (SELECT product, COUNT(1) AS story FROM zt_story WHERE deleted = \'0\' AND closedReason = \'done\' GROUP BY product) AS t4 ON t1.id = t4.product \nLEFT JOIN (SELECT product, COUNT(1) AS story FROM zt_story WHERE deleted = \'0\' AND ( closedReason = \'done\' OR status != \'closed\') GROUP BY product) AS t5 ON t1.id = t5.product \nWHERE t1.deleted = \'0\' AND t1.status != \'closed\' AND t1.shadow = \'0\' AND t1.vision = \'rnd\' AND t5.story IS NOT NULL \nORDER BY t1.order DESC', `stage` = 'published', `builtin` = 0 WHERE `id` = 1046;
UPDATE `zt_chart` SET `type` = 'cluBarY', `settings` = '[{\"type\":\"cluBarY\",\"xaxis\":[{\"field\":\"product\",\"name\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"group\":\"\"}],\"yaxis\":[{\"field\":\"fixedRate\",\"name\":\"\\u4fee\\u590d\\u7387\",\"valOrAgg\":\"sum\"}]}]',                                                            `fields` = '{\"product\":{\"name\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"object\":\"bug\",\"field\":\"product\",\"type\":\"string\"},\"program\":{\"name\":\"program\",\"object\":\"bug\",\"field\":\"program\",\"type\":\"string\"},\"productLine\":{\"name\":\"productLine\",\"object\":\"bug\",\"field\":\"productLine\",\"type\":\"string\"},\"fixedBug\":{\"name\":\"fixedBug\",\"object\":\"bug\",\"field\":\"fixedBug\",\"type\":\"string\"},\"totalBug\":{\"name\":\"totalBug\",\"object\":\"bug\",\"field\":\"totalBug\",\"type\":\"string\"},\"fixedRate\":{\"name\":\"\\u4fee\\u590d\\u7387\",\"object\":\"bug\",\"field\":\"fixedRate\",\"type\":\"number\"}}', `langs` = '{\"product\":{\"zh-cn\":\"\\u6240\\u5c5e\\u4ea7\\u54c1\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"program\":{\"zh-cn\":\"\\u9879\\u76ee\\u96c6\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"productLine\":{\"zh-cn\":\"\\u4ea7\\u54c1\\u7ebf\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"fixedBug\":{\"zh-cn\":\"\\u4fee\\u590dbug\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"totalBug\":{\"zh-cn\":\"bug\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"fixedRate\":{\"zh-cn\":\"bug\\u4fee\\u590d\\u7387\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"}}', `sql` = 'SELECT \n  t1.name AS product,\n  IFNULL(t2.name, \'/\') AS program,\n  IFNULL(t3.name, \'/\') AS productLine,\n  IFNULL(t4.bug, 0) AS fixedBug,\n  t5.bug AS totalBug,\n  ROUND(IFNULL(t4.bug, 0) / t5.bug * 100, 2) AS fixedRate\nFROM zt_product AS t1\nLEFT JOIN zt_project AS t2 ON t1.program = t2.id AND t2.type = \'program\' AND t2.grade = 1\nLEFT JOIN zt_module AS t3 ON t1.line = t3.id AND t3.type = \'line\'\nLEFT JOIN (SELECT product, COUNT(1) AS bug FROM zt_bug WHERE deleted = \'0\' AND resolution = \'fixed\' AND status = \'closed\' GROUP BY product) AS t4 ON t1.id = t4.product\nLEFT JOIN (SELECT product, COUNT(1) AS bug FROM zt_bug WHERE deleted = \'0\' AND (resolution = \'fixed\' OR resolution = \'postponed\' OR status = \'active\') GROUP BY product) AS t5 ON t1.id = t5.product\nWHERE t1.deleted = \'0\' AND t1.status != \'closed\' AND t1.shadow = \'0\' AND t1.vision = \'rnd\'  AND t5.bug IS NOT NULL\nORDER BY t1.order DESC', `stage` = 'published', `builtin` = 0 WHERE `id` = 1047;
UPDATE `zt_chart` SET `type` = 'cluBarY', `settings` = '[{\"type\":\"cluBarY\",\"xaxis\":[{\"field\":\"deptName\",\"name\":\"deptName\",\"group\":\"\"}],\"yaxis\":[{\"field\":\"count\",\"name\":\"count\",\"valOrAgg\":\"sum\"}]}]',                                                                                                   `fields` = '{\"deptName\":{\"name\":\"deptName\",\"object\":\"false\",\"field\":\"deptName\",\"type\":\"object\"},\"count\":{\"name\":\"count\",\"object\":\"false\",\"field\":\"count\",\"type\":\"object\"},\"deptOrder\":{\"name\":\"deptOrder\",\"object\":\"false\",\"field\":\"deptOrder\",\"type\":\"object\"}}', `langs` = '{\"deptName\":{\"zh-cn\":\"\\u90e8\\u95e8\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"count\":{\"zh-cn\":\"\\u4eba\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"deptOrder\":{\"zh-cn\":\"\\u987a\\u5e8f\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"}}', `sql` = 'SELECT IF(t3.id IS NOT NULL, t3.`name`, \"空\") AS deptName,count(1) as count, \nIF(t3.id IS NOT NULL, t3.`order`, 9999) AS deptOrder \nFROM zt_user AS t1 \nLEFT JOIN zt_dept AS t2 ON t1.dept = t2.id\nLEFT JOIN zt_dept AS t3 ON FIND_IN_SET(TRIM(\',\' FROM t3.path), TRIM(\',\' FROM t2.path)) AND t3.grade = \'1\'\nWHERE t1.deleted = \'0\'\nGROUP BY deptName, deptOrder \nORDER BY deptOrder  ASC', `stage` = 'published', `builtin` = 0 WHERE `id` = 1049;
UPDATE `zt_chart` SET `type` = 'pie',     `settings` = '[{\"type\":\"pie\",\"group\":[{\"field\":\"role\",\"name\":\"\\u804c\\u4f4d\",\"group\":\"\"}],\"metric\":[{\"field\":\"account\",\"name\":\"\\u7528\\u6237\\u540d\",\"valOrAgg\":\"count\"}]}]',                                                                                `fields` = '{\"account\":{\"name\":\"\\u7528\\u6237\\u540d\",\"object\":\"user\",\"field\":\"account\",\"type\":\"string\"},\"role\":{\"name\":\"\\u804c\\u4f4d\",\"object\":\"user\",\"field\":\"role\",\"type\":\"string\"}}', `langs` = '', `sql` = 'SELECT\n	account,\nCASE\n		ROLE \n		WHEN \'dev\' THEN\n		\"研发\" \n		WHEN \'qa\' THEN\n		\"测试\" \n		WHEN \'pm\' THEN\n		\"项目经理\" \n		WHEN \'others\' THEN\n		\"其他\" \n		WHEN \'td\' THEN\n		\"研发主管\" \n		WHEN \'pd\' THEN\n		\"产品主管\" \n		WHEN \'po\' THEN\n		\"产品经理\" \n		WHEN \'qd\' THEN\n		\"测试主管\" \n		WHEN \'top\' THEN\n		\"高层管理\" ELSE \"未知\" \n	END role \nFROM\n	zt_user \nWHERE\n	deleted = \'0\'', `stage` = 'published', `builtin` = 0 WHERE `id` = 1050;
UPDATE `zt_chart` SET `type` = 'cluBarY', `settings` = '[{\"type\":\"cluBarY\",\"xaxis\":[{\"field\":\"joinDate\",\"name\":\"joinDate\",\"group\":\"\"}],\"yaxis\":[{\"field\":\"count\",\"name\":\"count\",\"valOrAgg\":\"sum\"}]}]',                                                                                                   `fields` = '{\"count\":{\"name\":\"count\",\"object\":\"user\",\"field\":\"count\",\"type\":\"string\"},\"joinDate\":{\"name\":\"joinDate\",\"object\":\"user\",\"field\":\"joinDate\",\"type\":\"string\"}}', `langs` = '{\"count\":{\"zh-cn\":\"\\u4eba\\u6570\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"},\"joinDate\":{\"zh-cn\":\"\\u5de5\\u9f84\",\"zh-tw\":\"\",\"en\":\"\",\"de\":\"\",\"fr\":\"\"}}', `sql` = 'SELECT count(1) as count, \"0-1年\" as joinDate FROM zt_user WHERE deleted = \'0\' AND `join` > DATE_SUB(NOW(), INTERVAL 1 YEAR)\nunion\nSELECT count(1) as count, \"1-3年\" as joinDate FROM zt_user WHERE deleted = \'0\' AND `join` > DATE_SUB(NOW(), INTERVAL 3 YEAR) AND `join` <= DATE_SUB(NOW(), INTERVAL 1 YEAR)\nunion\nSELECT count(1) as count, \"3-5年\" as joinDate FROM zt_user WHERE deleted = \'0\' AND `join` > DATE_SUB(NOW(), INTERVAL 5 YEAR) AND `join` <= DATE_SUB(NOW(), INTERVAL 3 YEAR)\nunion\nSELECT count(1) as count, \"5-10年\" as joinDate FROM zt_user WHERE deleted = \'0\' AND `join` > DATE_SUB(NOW(), INTERVAL 10 YEAR) AND `join` <= DATE_SUB(NOW(), INTERVAL 5 YEAR)\nunion\nSELECT count(1) as count, \"10年以上\" as joinDate FROM zt_user WHERE deleted = \'0\' AND `join` < DATE_SUB(NOW(), INTERVAL 10 YEAR) AND LEFT(`join`, 4) != \'0000\'\nunion                                                                                                                                                                                                                                                          \nSELECT count(1) as count, \"未知\" as joinDate FROM zt_user WHERE deleted = \'0\' AND LEFT(`join`, 4) = \'0000\'', `stage` = 'published', `builtin` = 0 WHERE `id` = 1051;

ALTER TABLE zt_metric DROP INDEX `code`;

/* Add installed date to config. */
INSERT INTO `zt_config` ( `vision`, `owner`, `module`, `section`, `key`, `value` ) VALUES ('', 'system', 'common', 'global', 'installedDate', (SELECT LEFT( date, 10 ) AS date FROM zt_action WHERE LEFT ( date, 10 ) != '2012-06-05' AND LEFT ( date, 10 ) != '2021-04-28' AND date > '2009-03-14' ORDER BY id LIMIT 1));

REPLACE INTO `zt_chart`(`id`, `name`, `dimension`, `type`, `group`, `dataset`, `desc`, `settings`, `filters`, `step`, `fields`, `langs`, `sql`, `stage`, `builtin`, `objects`, `createdBy`, `createdDate`, `editedBy`, `editedDate`, `deleted`) VALUES (1030, '宏观数据-禅道使用时长', 1, 'card', '58', '', '', '{\"value\": {\"type\": \"value\", \"field\": \"period\", \"agg\": \"value\"}, \"title\": {\"type\": \"text\", \"name\": \"\"},\n\"type\": \"value\"\n}', '[]', 0, '', NULL, '	SELECT if(t2.`year` > 0, concat(t2.`year`, \'年\', t2.`day`, \'天\'), concat(t2.`day`, \'天\')) as period from (\r\nSELECT TIMESTAMPDIFF(YEAR,t1.firstDay,t1.today) AS `year`,DATEDIFF(DATE_SUB(t1.today,INTERVAL TIMESTAMPDIFF(YEAR,t1.firstDay,t1.today) YEAR), t1.firstDay) AS `day`  \r\nFROM (SELECT `value` AS firstDay, now() AS today FROM zt_config WHERE `owner` = \'system\' AND `key` = \'installedDate\') AS t1\r\n) t2', 'published', 1, '', 'system', '2022-12-07 14:59:41', '', '2022-12-07 14:59:41', 0);
REPLACE INTO `zt_chart`(`id`, `name`, `dimension`, `type`, `group`, `dataset`, `desc`, `settings`, `filters`, `step`, `fields`, `langs`, `sql`, `stage`, `builtin`, `objects`, `createdBy`, `createdDate`, `editedBy`, `editedDate`, `deleted`) VALUES (20015, '使用数据分析-上线时间', 1, 'card', '58', '0', ' ', '{\"value\": {\"type\": \"value\", \"field\": \"date\", \"agg\": \"value\"}, \"title\": {\"type\": \"text\", \"name\": \"\"}, \"type\": \"value\"}', '[]', 0, ' ', NULL, 'select `value` as date from zt_config where `owner` = \'system\' and `key` = \'installedDate\'', 'published', 1, ' ', 'system', '2023-08-16 15:32:10', 'admin', '2023-08-16 15:32:17', 0);

UPDATE `zt_cron` SET `type` = 'zentao' WHERE `command` = 'moduleName=metric&methodName=updateMetricLib';

CREATE TABLE `zt_queue` (
  `id` mediumint unsigned NOT NULL AUTO_INCREMENT,
  `cron` mediumint NOT NULL,
  `type` varchar(255) NOT NULL,
  `command` text NOT NULL,
  `status` enum('wait','doing','done') NOT NULL DEFAULT 'wait',
  `execId` int DEFAULT NULL,
  `createdDate` datetime NOT NULL,
  `deleted` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

UPDATE `zt_dimension` SET `desc` = '为管理层提供洞察力和决策支持，从而推动业务增长和发展' WHERE `id` = 1;
UPDATE `zt_dimension` SET `desc` = '识别项目管理流程中的关键步骤、瓶颈和性能指标，从而做出有针对性的改进措施，达到优化项目管理流程和降本增效的目的' WHERE `id` = 2;
UPDATE `zt_dimension` SET `desc` = '确保项目交付过程和成果符合预期的质量标准和要求，从而实现客户满意度、提高项目绩效、保障项目可持续性和促进持续改进' WHERE `id` = 3;

INSERT INTO `zt_prompt` (`name`, `model`, `module`, `source`, `targetForm`, `purpose`, `elaboration`, `role`, `characterization`, `createdBy`, `createdDate`, `status`) VALUES ('Bug转需求', 0, 'bug', ',bug.title,bug.steps,bug.severity,bug.pri,bug.status,bug.confirmed,bug.type,', 'story.create', '请将Bug转化为相应的研发需求。', '分条编写需求描述，分条编写验收标准，需求逻辑条理清晰。', '请你扮演一名资深的产品经理。', '负责产品战略、设计、开发、数据分析、用户体验、团队管理、沟通协调等方面，需要具备多种技能和能力，以实现产品目标和公司战略。', 'system', '2023-11-17 12:00:00', 'active');
INSERT INTO `zt_prompt` (`name`, `model`, `module`, `source`, `targetForm`, `purpose`, `elaboration`, `role`, `characterization`, `createdBy`, `createdDate`, `status`) VALUES ('拆分一个子计划', 0, 'productplan', ',productplan.title,productplan.desc,productplan.begin,productplan.end,', 'productplan.create', '根据给定计划名称、描述、计划开始时间和计划结束时间，将给定计划明确为其小范围的子计划。拆分出来的子计划可以更专注于给定计划中的某一类工作。	', '要求子计划的时间不能超出计划开始时间和计划结束时间，并且名称不能与原计划名称相同。润色子计划的描述。', '请你扮演一名资深的产品经理。', '负责产品计划、设计、用户体验等方面，需要具备多种技能和能力，以实现产品目标和公司战略。', 'system', '2023-11-17 12:00:00', 'active');
ALTER TABLE `zt_review` MODIFY `doc` varchar(255) DEFAULT '';
ALTER TABLE `zt_review` MODIFY `docVersion` varchar(255) DEFAULT '';

ALTER TABLE `zt_history`
CHANGE `old` `old` text NULL AFTER `field`,
CHANGE `new` `new` text NULL AFTER `old`,
CHANGE `diff` `diff` mediumtext NULL AFTER `new`;
