CREATE TABLE type (
id bigserial NOT NULL,
name text NOT NULL
UNIQUE,
PRIMARY KEY (id)
);
CREATE TABLE disc (
id bigserial NOT NULL,
type bigint NOT NULL
REFERENCES type (id)
ON DELETE RESTRICT,
PRIMARY KEY (id)
);
CREATE TABLE category (
id bigserial NOT NULL,
name text NOT NULL
UNIQUE,
type bigint NOT NULL
REFERENCES type (id)
ON DELETE RESTRICT,
PRIMARY KEY (id)
);
CREATE TABLE content (
id bigint NOT NULL
REFERENCES disc (id)
ON DELETE CASCADE,
title text NOT NULL,
person text DEFAULT null,
category bigint DEFAULT null
REFERENCES category (id)
ON DELETE RESTRICT,
UNIQUE (id, title)
);
CREATE INDEX content_id_index ON content (id);
GRANT ALL ON TABLE type, disc, category, content TO disc;
GRANT ALL ON type_id_seq, disc_id_seq, category_id_seq TO disc;