000001_init.up.sql
876 bytes
1CREATE TABLE IF NOT EXISTS channels (
2 id text NOT NULL PRIMARY KEY
3 , name text NOT NULL
4);
5
6CREATE TABLE IF NOT EXISTS videos (
7 id text NOT NULL PRIMARY KEY
8 , title text NOT NULL
9 , published_timestamp timestamp with time zone NOT NULL
10 , channel_id text NOT NULL REFERENCES channels(id)
11);
12
13CREATE TABLE IF NOT EXISTS users (
14 username text NOT NULL PRIMARY KEY
15 , password text NOT NULL
16);
17
18CREATE TABLE IF NOT EXISTS user_videos (
19 username text NOT NULL REFERENCES users(username)
20 , video_id text NOT NULL REFERENCES videos(id)
21 , watch_timestamp timestamp with time zone
22 , CONSTRAINT user_videos_pkey PRIMARY KEY (username, video_id)
23);
24
25CREATE TABLE IF NOT EXISTS user_subscriptions (
26 username text NOT NULL REFERENCES users(username)
27 , channel_id text NOT NULL REFERENCES channels(id)
28 , CONSTRAINT user_subscriptions_pkey PRIMARY KEY (channel_id, username)
29);