/*
 * Create initial portscout SQL tables
 *
 * Copyright (C) 2006-2008, Shaun Amott <shaun@inerd.com>
 * All rights reserved.
 *
 * $Id: pgsql_init.sql,v 1.9 2008/01/24 04:10:35 samott Exp $
 */

CREATE TABLE portdata (
	id serial UNIQUE,
	name text,
	distname text,
	ver text,
	newver text,
	comment text,
	cat text,
	dir text,
	home text,
	distfiles text,
	sufx text,
	mastersites text,
	checked timestamp,
	updated timestamp DEFAULT CURRENT_TIMESTAMP,
	maintainer text,
	status text,
	method integer,
	newurl text,
	ignore boolean DEFAULT FALSE,
	limitver text,
	masterport text,
	masterport_id integer DEFAULT 0,
	skipbeta boolean DEFAULT TRUE,
	limiteven boolean,
	limitwhich smallint,
	moved boolean DEFAULT FALSE,
	indexsite text,
	skipversions text,
	pcfg_static boolean DEFAULT FALSE,
	mailed text DEFAULT '',
	systemid integer
);

CREATE TABLE sitedata (
	id serial UNIQUE,
	failures integer DEFAULT 0,
	successes integer DEFAULT 0,
	liecount integer DEFAULT 0,
	robots integer DEFAULT 1,
	robots_paths text DEFAULT '',
	type text,
	host text,
	ignore boolean DEFAULT FALSE
);

CREATE TABLE moveddata (
	id serial UNIQUE,
	fromport text,
	toport text,
	date text,
	reason text
);

CREATE TABLE maildata (
	id serial UNIQUE,
	address text
);

CREATE TABLE systemdata (
	id serial UNIQUE,
	host text
);

CREATE TABLE allocators (
	id serial UNIQUE,
	seq integer NOT NULL,
	systemid integer REFERENCES systemdata (id),
	allocator text
);

CREATE TABLE portscout (
	dbver integer
);

INSERT
  INTO portscout (dbver)
VALUES (2008012301);

CREATE
 INDEX portdata_index_name
    ON portdata (name);

CREATE
 INDEX portdata_index_maintainer
    ON portdata (maintainer);

CREATE
 INDEX portdata_index_lower_maintainer
    ON portdata (lower(maintainer));

CREATE
 INDEX portdata_index_masterport_id
    ON portdata (masterport_id);
