| 1 |
--DROP TABLE comments; DROP TABLE entries; DROP TABLE categories; DROP TABLE users; |
|---|
| 2 |
|
|---|
| 3 |
CREATE TABLE users ( |
|---|
| 4 |
id serial NOT NULL PRIMARY KEY, |
|---|
| 5 |
username text NOT NULL UNIQUE, |
|---|
| 6 |
password text NOT NULL, |
|---|
| 7 |
type integer DEFAULT 1, |
|---|
| 8 |
name text, |
|---|
| 9 |
title text, |
|---|
| 10 |
description text, |
|---|
| 11 |
css text DEFAULT 'blog.css', |
|---|
| 12 |
enabled bool NOT NULL DEFAULT true, |
|---|
| 13 |
moderate bool NOT NULL DEFAULT true, |
|---|
| 14 |
editor bool NOT NULL DEFAULT true |
|---|
| 15 |
); |
|---|
| 16 |
|
|---|
| 17 |
CREATE TABLE categories ( |
|---|
| 18 |
id serial NOT NULL PRIMARY KEY, |
|---|
| 19 |
name text NOT NULL, |
|---|
| 20 |
description text, |
|---|
| 21 |
user_id integer REFERENCES users ON DELETE CASCADE |
|---|
| 22 |
); |
|---|
| 23 |
|
|---|
| 24 |
CREATE TABLE entries ( |
|---|
| 25 |
id serial NOT NULL PRIMARY KEY, |
|---|
| 26 |
category integer REFERENCES categories ON DELETE RESTRICT NOT NULL, |
|---|
| 27 |
subject text NOT NULL, |
|---|
| 28 |
shortsubject text NOT NULL, |
|---|
| 29 |
body text NOT NULL, |
|---|
| 30 |
"timestamp" timestamp(0) with time zone DEFAULT ('now'::text)::timestamp(0) with time zone, |
|---|
| 31 |
user_id integer REFERENCES users ON DELETE CASCADE NOT NULL |
|---|
| 32 |
); |
|---|
| 33 |
CREATE UNIQUE INDEX entries_shortsubject_key ON entries (shortsubject, user_id); |
|---|
| 34 |
|
|---|
| 35 |
CREATE TABLE comments ( |
|---|
| 36 |
id serial NOT NULL PRIMARY KEY, |
|---|
| 37 |
post integer REFERENCES entries ON DELETE CASCADE NOT NULL, |
|---|
| 38 |
"timestamp" timestamp(0) with time zone DEFAULT ('now'::text)::timestamp(0) with time zone, |
|---|
| 39 |
name text NOT NULL, |
|---|
| 40 |
email text, |
|---|
| 41 |
body text NOT NULL, |
|---|
| 42 |
host text NOT NULL, |
|---|
| 43 |
moderated bool NOT NULL DEFAULT false, |
|---|
| 44 |
spam bool NOT NULL DEFAULT false |
|---|
| 45 |
); |
|---|
| 46 |
|
|---|
| 47 |
CREATE TABLE authorised_emails ( |
|---|
| 48 |
user_id integer REFERENCES users ON DELETE CASCADE NOT NULL, |
|---|
| 49 |
email text NOT NULL, |
|---|
| 50 |
name text |
|---|
| 51 |
); |
|---|
| 52 |
CREATE UNIQUE INDEX authorised_emails_email_key ON authorised_emails (email, user_id); |
|---|