<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
$success=true;

set_time_limit(0);

if (Db::i()->selectCell("SELECT module_id FROM ?_modules WHERE module='bug_tracker'")) {
	Db::i()->query(
		"ALTER TABLE ?_bt_versions ADD `unsupported` TINYINT NOT NULL DEFAULT '0'"
	);
	Db::i()->query("INSERT IGNORE INTO ?_bt_versions (`version_id`, `version`, `unsupported`) VALUES ('-1', 'HEAD', '0');");
	Db::i()->query(
		"ALTER TABLE ?_bt_versions
		CHANGE `version` `name` varchar(15) COLLATE 'utf8_general_ci' NOT NULL AFTER `version_id`;"
	);
	Db::i()->query("ALTER TABLE ?_bt_posts ADD `first` tinyint NOT NULL DEFAULT '0';");
	Db::i()->query(
		"UPDATE ?_bt_posts as t1, (SELECT MIN(post_id) as post_id, bug_id
		FROM ?_bt_posts
		GROUP BY bug_id) as t2
		SET t1.first=1 WHERE t1.post_id=t2.post_id"
	);

	Db::i()->query(
		"ALTER TABLE ?_bt_bugs
		CHANGE `version_id` `version_id` int(11) NOT NULL AFTER `bug_id`,
		CHANGE `summary` `summary` tinytext COLLATE 'utf8_general_ci' NOT NULL AFTER `version_id`,
		CHANGE `author_id` `author_id` int(11) NOT NULL AFTER `type`,
		CHANGE `last_update` `last_update` int(10) unsigned NULL AFTER `author_id`,
		CHANGE `approver_id` `approver_id` int(11) NOT NULL AFTER `importance`,
		CHANGE `performer_id` `performer_id` int(11) NOT NULL AFTER `status`;"
	);

	Db::i()->query(
		"ALTER TABLE ?_bt_files
		CHANGE `post_id` `post_id` int(11) NOT NULL AFTER `file_id`;"
	);

	Db::i()->query(
		"ALTER TABLE ?_bt_posts
		CHANGE `user_id` `user_id` int(11) NOT NULL AFTER `post_id`,
		CHANGE `bug_id` `bug_id` int(11) NOT NULL AFTER `user_id`,
		CHANGE `msg` `msg` text COLLATE 'utf8_general_ci' NOT NULL AFTER `bug_id`;"
	);

}



