<?php
/*=====================================================================*\
|| ###################################################################
|| # Bugdar
|| # Copyright (c)2004-2009 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

$schema['adminsession'] = "
CREATE TABLE " . TABLE_PREFIX . "adminsession
(
	sessionid varchar(250) NOT NULL,
	userid int unsigned NOT NULL,
	dateline int unsigned NOT NULL,
	PRIMARY KEY (sessionid)
);";

$schema['attachment'] = "
CREATE TABLE " . TABLE_PREFIX . "attachment
(
	attachmentid int unsigned NOT NULL AUTO_INCREMENT,
	bugid int unsigned NOT NULL,
	filename varchar(255) NOT NULL,
	mimetype varchar(255) NOT NULL,
	filesize bigint unsigned NOT NULL,
	attachment blob NOT NULL,
	description varchar(255) NOT NULL,
	dateline bigint unsigned NOT NULL,
	userid int unsigned NOT NULL,
	obsolete bool NOT NULL,
	PRIMARY KEY (attachmentid)
);";

$schema['automation'] = "
CREATE TABLE " . TABLE_PREFIX . "automation
(
	actionid int unsigned NOT NULL AUTO_INCREMENT,
	name varchar(255) NOT NULL,
	description text NOT NULL,
	fieldchanges text NOT NULL,
	comment text NOT NULL,
	PRIMARY KEY (actionid)
);";

$schema['bug'] = "
CREATE TABLE " . TABLE_PREFIX . "bug
(
	bugid int unsigned NOT NULL AUTO_INCREMENT,
	userid int unsigned NOT NULL,
	dateline bigint unsigned NOT NULL,
	product int unsigned NOT NULL,
	component int unsigned NOT NULL,
	version int unsigned NOT NULL,
	summary varchar(255) NOT NULL,
	priority int unsigned NOT NULL,
	severity int unsigned NOT NULL,
	status int unsigned NOT NULL,
	resolution int unsigned NOT NULL,
	assignedto int unsigned NOT NULL,
	duplicateof int unsigned NOT NULL,
	dependency text NOT NULL,
	hidden smallint unsigned NOT NULL,
	initialreport int unsigned NOT NULL,
	lastposttime bigint unsigned NOT NULL,
	lastpostby int unsigned NOT NULL,
	hiddenlastposttime int unsigned NOT NULL,
	hiddenlastpostby int unsigned NOT NULL,
	username varchar(255) NOT NULL,
	lastpostbyname varchar(255) NOT NULL,
	hiddenlastpostbyname varchar(255) NOT NULL,
	PRIMARY KEY (bugid),
	FULLTEXT KEY summary (summary)
);";

$schema['bugfield'] = "
CREATE TABLE " . TABLE_PREFIX . "bugfield
(
	fieldid int unsigned NOT NULL AUTO_INCREMENT,
	name varchar(255) NOT NULL,
	description text NOT NULL,
	type varchar(50) NOT NULL,
	selects text NOT NULL,
	required smallint NOT NULL,
	cansearch smallint NOT NULL,
	regexmatch text NOT NULL,
	defaultvalue text NOT NULL,
	usedefault smallint NOT NULL,
	maxlength smallint unsigned NOT NULL,
	PRIMARY KEY (fieldid)
);";

$schema['bugfieldpermission'] = "
CREATE TABLE " . TABLE_PREFIX . "bugfieldpermission
(
	usergroupid int unsigned NOT NULL,
	fieldid int unsigned NOT NULL,
	mask int unsigned NOT NULL,
	PRIMARY KEY (usergroupid, fieldid)
);";

$schema['comment'] = "
CREATE TABLE " . TABLE_PREFIX . "comment
(
	commentid int unsigned NOT NULL AUTO_INCREMENT,
	bugid int unsigned NOT NULL,
	userid int unsigned NOT NULL,
	dateline bigint unsigned NOT NULL,
	comment text NOT NULL,
	comment_parsed text NOT NULL,
	hidden smallint unsigned NOT NULL,
	parselinks bool NULL,
	PRIMARY KEY (commentid),
	FULLTEXT KEY comment (comment)
);";

$schema['datastore'] = "
CREATE TABLE " . TABLE_PREFIX . "datastore
(
	title varchar(255) NOT NULL,
	data text NOT NULL,
	PRIMARY KEY (title)
);";

$schema['favorite'] = "
CREATE TABLE " . TABLE_PREFIX . "favorite
(
	userid int unsigned NOT NULL,
	bugid int unsigned NOT NULL,
	PRIMARY KEY (userid, bugid)
);";

$schema['fieldhelp'] = "
CREATE TABLE " . TABLE_PREFIX . "fieldhelp
(
	keystring varchar(255) NOT NULL,
	title varchar(255) NOT NULL,
	body text NOT NULL,
	PRIMARY KEY (keystring)
);";

$schema['history'] = "
CREATE TABLE " . TABLE_PREFIX . "history
(
	historyid bigint unsigned NOT NULL AUTO_INCREMENT,
	bugid int unsigned NOT NULL,
	attachmentid int unsigned NOT NULL,
	commentid int unsigned NOT NULL,
	dateline bigint unsigned NOT NULL,
	userid int unsigned NOT NULL,
	field varchar(255) NOT NULL,
	original text NOT NULL,
	changed text NOT NULL,
	PRIMARY KEY (historyid)
);";

$schema['language'] = "
CREATE TABLE " . TABLE_PREFIX . "language
(
	languageid int unsigned NOT NULL AUTO_INCREMENT,
	title varchar(255) NOT NULL,
	langcode varchar(5) NOT NULL,
	charset varchar(15) NOT NULL,
	direction char(3) NOT NULL,
	userselect smallint unsigned NOT NULL,
	PRIMARY KEY (languageid),
	UNIQUE KEY languagecode (langcode)
);";

$schema['passwordreset'] = "
CREATE TABLE " . TABLE_PREFIX . "passwordreset
(
	activatorid varchar(250) NOT NULL,
	userid int NOT NULL,
	dateline int NOT NULL,
	PRIMARY KEY (activatorid)
);";

$schema['permission'] = "
CREATE TABLE " . TABLE_PREFIX . "permission
(
	usergroupid int unsigned NOT NULL,
	productid int unsigned NOT NULL,
	mask int NOT NULL,
	PRIMARY KEY (usergroupid, productid)
);";

$schema['priority'] = "
CREATE TABLE " . TABLE_PREFIX . "priority
(
	priorityid int unsigned NOT NULL AUTO_INCREMENT,
	priority varchar(255) NOT NULL,
	displayorder int unsigned NOT NULL,
	PRIMARY KEY (priorityid)
);";

$schema['product'] = "
CREATE TABLE " . TABLE_PREFIX . "product
(
	productid int unsigned NOT NULL AUTO_INCREMENT,
	parentid int unsigned NULL,
	displayorder int unsigned NOT NULL,
	title varchar(255) NOT NULL,
	description text NOT NULL,
	PRIMARY KEY (productid)
);";

$schema['resolution'] = "
CREATE TABLE " . TABLE_PREFIX . "resolution
(
	resolutionid int unsigned NOT NULL AUTO_INCREMENT,
	resolution varchar(255) NOT NULL,
	displayorder int unsigned NOT NULL,
	PRIMARY KEY (resolutionid)
);";

$schema['search'] = "
CREATE TABLE " . TABLE_PREFIX . "search
(
	searchid int unsigned NOT NULL AUTO_INCREMENT,
	userid int unsigned NOT NULL,
	dateline bigint unsigned NOT NULL,
	query text NOT NULL,
	ids text NOT NULL,
	orderby text NOT NULL,
	hilight varchar(255) NOT NULL,
	resultcount int NULL,
	name varchar(250) NULL,
	PRIMARY KEY (searchid)
);";

$schema['setting'] = "
CREATE TABLE " . TABLE_PREFIX . "setting
(
	varname varchar(255) NOT NULL,
	value text NOT NULL,
	PRIMARY KEY (varname)
);";

$schema['severity'] = "
CREATE TABLE " . TABLE_PREFIX . "severity
(
	severityid int unsigned NOT NULL AUTO_INCREMENT,
	severity varchar(255) NOT NULL,
	displayorder int unsigned NOT NULL,
	PRIMARY KEY (severityid)
);";

$schema['status'] = "
CREATE TABLE " . TABLE_PREFIX . "status
(
	statusid int unsigned NOT NULL AUTO_INCREMENT,
	status varchar(255) NOT NULL,
	displayorder int unsigned NOT NULL,
	color varchar(10) NOT NULL,
	PRIMARY KEY (statusid)
);";

$schema['template'] = "
CREATE TABLE " . TABLE_PREFIX . "template
(
	filename varchar(255) NOT NULL,
	template text NOT NULL,
	timestamp int unsigned NOT NULL,
	PRIMARY KEY (filename)
);";

$schema['user'] = "
CREATE TABLE " . TABLE_PREFIX . "user
(
	userid int unsigned NOT NULL AUTO_INCREMENT,
	email varchar(255) NOT NULL,
	displayname varchar(255) NOT NULL,
	usergroupid int unsigned NOT NULL,
	groupids text NULL,
	password varchar(32) NOT NULL,
	salt varchar(15) NOT NULL,
	authkey varchar(65) NOT NULL,
	showemail smallint unsigned NOT NULL,
	showcolors bool NULL,
	languageid int unsigned NOT NULL,
	timezone float NOT NULL,
	usedst bool NOT NULL,
	hidestatuses text NOT NULL,
	defaultsortkey varchar(50) NULL,
	defaultsortas varchar(10) NULL,
	columnoptions text NULL,
	authid varchar(255) NULL,
	PRIMARY KEY (userid)
);";

$schema['useractivation'] = "
CREATE TABLE " . TABLE_PREFIX . "useractivation
(
	activator varchar(25) NOT NULL,
	userid int unsigned NOT NULL,
	dateline int unsigned NOT NULL,
	usergroupid int unsigned NOT NULL,
	PRIMARY KEY (activator)
);";

$schema['useremail'] = "
CREATE TABLE " . TABLE_PREFIX . "useremail
(
	userid int unsigned NOT NULL,
	mask int unsigned NOT NULL,
	relation int unsigned NOT NULL
);";

$schema['usergroup'] = "
CREATE TABLE " . TABLE_PREFIX . "usergroup
(
	usergroupid int unsigned NOT NULL AUTO_INCREMENT,
	title varchar(255) NOT NULL,
	displaytitle varchar(255) NOT NULL,
	permissions int unsigned NOT NULL,
	PRIMARY KEY (usergroupid)
);";

$schema['version'] = "
CREATE TABLE " . TABLE_PREFIX . "version
(
	versionid int unsigned NOT NULL AUTO_INCREMENT,
	productid int unsigned NOT NULL,
	version varchar(255) NOT NULL,
	displayorder int unsigned NOT NULL,
	obsolete bool NULL,
	PRIMARY KEY (versionid)
);";

$schema['vote'] = "
CREATE TABLE " . TABLE_PREFIX . "vote
(
	bugid int unsigned NOT NULL,
	userids text NOT NULL,
	votefor int unsigned NOT NULL,
	voteagainst int unsigned NOT NULL,
	PRIMARY KEY (bugid)
);";

?>