-- Catalogs
create table catalogs (
	id	serial,
	title	text not null,
	path	text,
	date	timestamp not null default now(),
	primary key(id)
);

create table catalog_webarchive (
	uri	text not null,			-- unique index
	last_crawled timestamp,
	primary key(id)
) inherits (catalogs) ;

-- Entries in Catalog
create table entries (
	id	serial,
	title	text,
	path	text,
	date	timestamp not null default now(),
	primary key(id)
);

create table catalog_entry (
	catalog_id int references catalogs(id),
	entry_id int references entries(id),
	e_type text not null,			-- index
	primary key (catalog_id, entry_id)
);

-- Pg General Bits entries
create table entries_pgbits (
	issue	int not null,			-- unique index
	primary key(id)
) inherits (entries) ;

-- Items for each Entry
create table items (
	id	serial,
	title	text,
	entry_id int references entries(id),

	i_type	text not null,
	date timestamp not null default now(),
	primary key(id)
);

-- HyperEstraier support table
create table items_est (
	path	text,			-- unique index
	uri	text not null,		-- unique index
	size	int,
	primary key(id)
) inherits (items) ;

-- Tags for Entries
create table tags (
	id	serial,
	title	text,			-- index
	date timestamp not null default now(),
	primary key(id)
);

create table entry_tag (
	entry_id int references entries(id),
	tag_id int references tags(id),
	value text not null,
	t_type text not null,		-- index
	date timestamp not null default now(),
	primary key (entry_id, tag_id)
);

