
CREATE TABLE "point"  ( 
	"id"        	int(10) UNSIGNED AUTO_INCREMENT NOT NULL,
	"timestamp" 	timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	"createDate"	timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
	"free"      	int(10) UNSIGNED NULL,
	"free_cache"	int(10) UNSIGNED NULL,
	"used"      	int(10) UNSIGNED NOT NULL,
	"used_cache"	int(10) UNSIGNED NOT NULL,
	"swap"      	int(10) UNSIGNED NOT NULL,
	PRIMARY KEY("id")
);

CREATE TABLE "process_point"  ( 
	"pointId"      	int(10) UNSIGNED NOT NULL,
	"processId"    	int(10) UNSIGNED NOT NULL,
	"instanceCount"	tinyint(3) UNSIGNED NOT NULL,
	"pageFaults"   	int(10) UNSIGNED NOT NULL,
	"resident"     	int(10) UNSIGNED NOT NULL,
	"virtual"      	int(10) UNSIGNED NOT NULL,
	"notes"        	varchar(255) NULL,
	PRIMARY KEY("pointId","processId")
);

CREATE TABLE "process"  ( 
	"id"   	int(10) UNSIGNED AUTO_INCREMENT NOT NULL,
	"name" 	varchar(255) NOT NULL,
	"alias"	varchar(255) NULL,
	"color"	char(6) NULL,
	PRIMARY KEY("id")
);


CREATE INDEX "k_processId"
	ON "process_point"("processId");

CREATE UNIQUE INDEX "uk_name"
	ON "process"("name");

ALTER TABLE "process"
	ADD CONSTRAINT "uk_name"
	UNIQUE ("name");

ALTER TABLE "process_point"
	ADD CONSTRAINT "fk_process_point_processId"
	FOREIGN KEY("processId")
	REFERENCES "process"("id");

ALTER TABLE "process_point"
	ADD CONSTRAINT "fk_process_point_pointId"
	FOREIGN KEY("pointId")
	REFERENCES "point"("id");
