· 6 years ago · Jul 14, 2019, 01:26 PM
1create table if not exists public.song
2(
3 song_id serial not null
4 constraint songs_pk
5 primary key,
6 hash text not null,
7 name text not null,
8 length integer
9);
10
11create table if not exists public.album
12(
13 album_id serial not null
14 constraint album_pk
15 primary key,
16 name text not null,
17 artist text not null,
18 length integer,
19 release date,
20 art bytea
21);
22
23create table if not exists public.song_album
24(
25 song_id integer not null
26 constraint song_album_song_id_fkey
27 references public.song,
28 album_id integer not null
29 constraint song_album_album_id_fkey
30 references public.album,
31 constraint song_album_id
32 primary key (song_id, album_id)
33);
34
35create table if not exists public.playlist
36(
37 playlist_id serial not null
38 constraint playlist_pk
39 primary key,
40 name text not null,
41 art bytea
42);
43
44create table if not exists public.song_playlist
45(
46 song_id integer not null
47 constraint song_playlist_song_id_fkey
48 references public.song,
49 playlist_id integer not null
50 constraint song_playlist_playlist_id_fkey
51 references public.playlist,
52 constraint song_playlist_id
53 primary key (song_id, playlist_id)
54);
55
56create table if not exists public.genre
57(
58 genre_id serial not null
59 constraint genre_pk
60 primary key,
61 name text not null
62);
63
64create table if not exists public.song_genre
65(
66 song_id integer not null
67 constraint song_genre_song_id_fkey
68 references public.song,
69 genre_id integer not null
70 constraint song_genre_genre_id_fkey
71 references public.genre,
72 constraint song_genre_id
73 primary key (song_id, genre_id)
74);