forked from AndreaM2429/Catalog_App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
58 lines (50 loc) · 1.27 KB
/
schema.sql
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- Create a database called catalog_app
CREATE DATABASE catalog_app;
\c catalog_app;
-- create items table (parent class)
CREATE TABLE items (
id SERIAL PRIMARY KEY,
genre_id int REFERENCES genre(id),
author_id int REFERENCES authors(id),
label_id int REFERENCES label(id),
publish_date DATE,
archived BOOLEAN
);
-- create the games table (child class of Items)
CREATE TABLE games (
id INT PRIMARY KEY,
multiplayer BOOLEAN,
last_played_at DATE REFERENCES item(publish_date),
item_id int REFERENCES items(id)
);
-- create authors table
CREATE TABLE authors (
id SERIAL PRIMARY KEY,
first_name VARCHAR(255),
last_name VARCHAR(255)
);
-- Add music_album table (child class of Items)
CREATE TABLE music_album(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
on_spotify BOOLEAN,
archived BOOLEAN,
item_id int REFERENCES item(id)
);
-- Add genre table
CREATE table genre (
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR(255),
);
-- Add label table
CREATE TABLE label(
id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
title varchar(100),
color varchar(100)
);
-- Add book table
CREATE TABLE book(
id int PRIMARY KEY REFERENCES item(id),
publisher varchar(100),
cover_state varchar(64),
item_id int REFERENCES item(id)
);