/*clean house first*/
drop database if exists cluelesspc;

/*create a new instance*/
create database if not exists cluelesspc;
use cluelesspc;

drop table if exists tbluser;
create table if not exists tbluser
(
	userid int(10) unsigned not null auto_increment,
	loginid varchar(100) not null,
	password varchar(100) not null,
	firstname varchar(100) not null,
	lastname varchar(100) not null,
	primary key (userid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tbluserlanguage;
create table if not exists tbluserlanguage
(
	userid int(10) unsigned not null,
	languageid int(10) unsigned not null,
	sortorder int(10),
	primary key (userid, languageid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tbllanguage;
create table if not exists tbllanguage
(
	languageid int(10) unsigned not null auto_increment,
	name varchar(100) not null,
	primary key (languageid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tbldocument;
create table if not exists tbldocument
(
	documentid int(10) unsigned not null auto_increment,
	documenttypeid int(10) unsigned not null,
	name varchar(100) not null,
	filename varchar(100) not null,
	primary key (documentid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tbldoccom;
create table if not exists tbldoccom
(
	documentid int(10) unsigned not null,
	componentid int(10) unsigned not null,
	languageid int(10) unsigned not null,
	sortorder int(10) unsigned not null,
	primary key (documentid, componentid, languageid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tblcomponent;
create table if not exists tblcomponent
(
	componentid int(10) unsigned not null auto_increment,
	componenttypeid int(10) unsigned not null,
	name varchar(100) not null,
	content text,
	filename varchar(100),
	path varchar(100),
	size varchar(100),
	primary key (componentid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tblcomponenttype;
create table if not exists tblcomponenttype
(
	componenttypeid int(10) unsigned not null auto_increment,
	name varchar(100) not null,
	primary key (componenttypeid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tblscore;
create table if not exists tblscore
(
	userid int(10) unsigned not null,
	documentid int(10) unsigned not null,
	score int(10) unsigned not null,
	primary key (userid,documentid)
) engine=myisam default charset=latin1 auto_increment=1;

drop table if exists tbldocumenttype;
create table if not exists tbldocumenttype
(
	documenttypeid int(10) unsigned not null auto_increment,
	name varchar(100) not null,
	primary key (documenttypeid)
) engine=myisam default charset=latin1 auto_increment=1;