create table category(
	catId		int unsigned primary key auto_increment,
	parentId	int unsigned not null,
	catName		varchar(100),
	catDesc		text
	);

create table problem(
	probId		int unsigned primary key auto_increment,
	catId		int unsigned not null,
	status		int unsigned not null default 10,
	authorId	int unsigned not null default 0,
	probName	varchar(100),
	probText	text,
	probSol		text,
	created		date default 'now',
	modified	timestamp not null,
	modName		varchar(255),
	difficulty	int unsigned not null default 3,
	originality	int unsigned not null default 3
	);

CREATE TABLE user (
        usrId		int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        login           varchar(30) NOT NULL,
        password        varchar(30) NOT NULL,
        email           varchar(100),
        access          int UNSIGNED NOT NULL DEFAULT 10,
	usrName		varchar(60),
	homePage	varchar(100),
	score		int not null default 0
        );

CREATE TABLE comment (
	comId		int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	probId		int unsigned not null,
	authorId	int unsigned not null default 0,
	authorName	varchar(40),
	subject		varchar(255),
	posted		datetime not null default '0000-00-00',
	status		int unsigned not null default 0,
	comText		text
	);

CREATE TABLE uservisit (
	usrId		int unsigned not null,
	usrName		varchar(40),
	visitDate	timestamp
	);	

CREATE TABLE rating (
	usrId		int unsigned not null,
	probId		int unsigned not null,
	rating 		int unsigned not null
	);

create table forum ( 
	forumId 	int unsigned not null auto_increment primary key,
	forumName	varchar(100) not null,
	forumDesc	varchar(255) not null,
	viewLevel	int unsigned not null default 0,
	postLevel	int unsigned not null default 0
	);

CREATE TABLE forumthread (
	threadId	int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	forumId		int UNSIGNED NOT NULL,
	subject		varchar(100),
	authorId	int UNSIGNED,
	authorName	varchar(40),
	started		datetime,
	updated		datetime,
	posts		int UNSIGNED NOT NULL DEFAULT 1
	);
	
CREATE TABLE forumpost (
	postId 		int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	threadId 	int UNSIGNED NOT NULL,
	forumId		int UNSIGNED NOT NULL,
	subject		varchar(100),
	post		text,
	authorId	int UNSIGNED,
	authorName	varchar(40),
	posted 		datetime
	);	

CREATE TABLE solutionpush (
	probId	int UNSIGNED NOT NULL PRIMARY KEY,
	pushed	datetime
	);
