-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
29 lines (26 loc) · 779 Bytes
/
schema.sql
File metadata and controls
29 lines (26 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
CREATE TABLE IF NOT EXISTS agents (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS authors (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
website TEXT,
agent_id BIGINT NOT NULL,
FOREIGN KEY (agent_id) REFERENCES agents(id) ON DELETE RESTRICT
);
CREATE TABLE IF NOT EXISTS books (
id BIGSERIAL PRIMARY KEY,
title TEXT NOT NULL,
description TEXT NOT NULL,
cover TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS book_authors (
id BIGSERIAL PRIMARY KEY,
book_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE,
FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE,
UNIQUE (book_id,author_id)
);