Closed soerenmeier closed 1 month ago
CREATE TABLE entry (
id TEXT PRIMARY KEY,
tmdb_id BIGINT,
type SMALLINT CHECK (type IN (0, 1)),
name TEXT NOT NULL,
original_name TEXT,
description TEXT,
poster TEXT,
background TEXT,
rating FLOAT,
duration INTEGER,
first_publication SMALLINT NOT NULL,
created_on TIMESTAMP NOT NULL,
last_updated TIMESTAMP NOT NULL,
INDEX (tmdb_id)
);
CREATE TABLE season (
id TEXT PRIMARY KEY,
entry_id TEXT NOT NULL REFERENCES entry(id),
season SMALLINT NOT NULL,
name TEXT NOT NULL,
original_name TEXT,
created_on TIMESTAMP NOT NULL,
UNIQUE (entry_id, season)
);
CREATE TABLE episode (
id TEXT PRIMARY KEY,
season_id TEXT NOT NULL REFERENCES season(id),
episode SMALLINT NOT NULL,
name TEXT NOT NULL,
original_name TEXT,
publication_year SMALLINT,
created_on TIMESTAMP NOT NULL,
description TEXT,
duration INTEGER,
UNIQUE (season_id, episode)
);
CREATE TABLE media_files (
id TEXT PRIMARY KEY,
entry_id TEXT REFERENCES entry(id),
episode_id TEXT REFERENCES episode(id),
name TEXT NOT NULL,
size INTEGER NOT NULL,
width SMALLINT,
height SMALLINT,
intro_time INTEGER,
outro_time INTEGER,
created_on TIMESTAMP NOT NULL
);
CREATE TABLE entry_genres (
entry_id TEXT NOT NULL REFERENCES entry(id),
genres_id INTEGER NOT NULL,
PRIMARY KEY (entry_id, genres_id)
);
CREATE TABLE progress (
entry_id TEXT REFERENCES entry(id),
episode_id TEXT REFERENCES episode(id),
user_id TEXT NOT NULL,
progress FLOAT NOT NULL,
created_on TIMESTAMP NOT NULL,
updated_on TIMESTAMP NOT NULL,
last_watch TIMESTAMP,
PRIMARY KEY (entry_id, episode_id, user_id)
);
This db might be less efficient in queries than the current one, but it is more logical and better uses the strenghts of a relation db. This adds a few new fields like description, poster, background, rating, duration, resolution, categories and more.