create table Projects (
	portname	varchar(255) not null,
	portsection	varchar(255) not null,
	tarfilename	varchar(255) not null,
	slocsize	int,
	primary key (portname, portsection, tarfilename)
) TYPE=InnoDB;

create table Files (
	filepath	varchar(255) not null,
	portname	varchar(255) not null,
	portsection	varchar(255) not null,
	tarfilename	varchar(255) not null,
	size            int,
	lang		varchar(10),
	filemd5		char(32) not null,
	primary key (filepath, portname, portsection, filemd5),
	foreign key (portname, portsection, tarfilename) references Projects(portname, portsection, tarfilename)
) TYPE=InnoDB;

create table CMetrics (
	md5		char(32) not null,
	sloc		int,
	loc		int,
	blk_lines	int,
	comment_lines	int,
	comments	int,
	mccabe		int,
	returns		int,
	halstead_length	int,
	halstead_volume	int,
	halstead_level	float,
	halstead_md	int,
	functions	int,
	primary key (md5),
	foreign key (md5) references Files(filemd5)
) TYPE=InnoDB;

create Table AutoFiles (
	md5		char(32) not null,
	is_auto		bool,
	primary key (md5),
	foreign key (md5) references UniqueFiles(filemd5)
) TYPE=InnoDB;

create table CFunctions (md5 char(32),
       	     		funcname varchar(255),
			sloc int,mccabe int,
			numreturns int,
			primary key (md5,funcname,sloc,mccabe,numreturns)
) TYPE=InnoDB;
