-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.sql
73 lines (56 loc) · 2.17 KB
/
database.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
CREATE DATABASE musicas;
CREATE TABLE public.artistas (
id_artista VARCHAR NOT NULL,
nome VARCHAR NOT NULL,
CONSTRAINT artistas_pk PRIMARY KEY (id_artista)
);
CREATE TABLE public.musicas (
id_musica VARCHAR NOT NULL,
id_artista VARCHAR NOT NULL,
nome VARCHAR NOT NULL,
duracao_segundos INTEGER NOT NULL,
CONSTRAINT musicas_pk PRIMARY KEY (id_musica)
);
CREATE TABLE public.usuarios_spotify (
id_usuario VARCHAR NOT NULL,
nome_usuario VARCHAR NOT NULL,
CONSTRAINT usuarios_spotify_pk PRIMARY KEY (id_usuario)
);
CREATE TABLE public.playlists (
id_playlist VARCHAR NOT NULL,
id_usuario VARCHAR NOT NULL,
nome_playlist VARCHAR NOT NULL,
CONSTRAINT playlists_pk PRIMARY KEY (id_playlist)
);
CREATE SEQUENCE public.musicas_playlist_id_seq;
CREATE TABLE public.musicas_playlist (
id INTEGER NOT NULL DEFAULT nextval('public.musicas_playlist_id_seq'),
id_playlist VARCHAR NOT NULL,
id_musica VARCHAR NOT NULL,
CONSTRAINT musicas_playlist_pk PRIMARY KEY (id)
);
ALTER SEQUENCE public.musicas_playlist_id_seq OWNED BY public.musicas_playlist.id;
ALTER TABLE public.musicas ADD CONSTRAINT artistas_musicas_fk
FOREIGN KEY (id_artista)
REFERENCES public.artistas (id_artista)
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE;
ALTER TABLE public.musicas_playlist ADD CONSTRAINT musicas_musicas_playlist_fk
FOREIGN KEY (id_musica)
REFERENCES public.musicas (id_musica)
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE;
ALTER TABLE public.playlists ADD CONSTRAINT usuarios_spotify_playlists_fk
FOREIGN KEY (id_usuario)
REFERENCES public.usuarios_spotify (id_usuario)
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE;
ALTER TABLE public.musicas_playlist ADD CONSTRAINT playlists_musicas_playlist_fk
FOREIGN KEY (id_playlist)
REFERENCES public.playlists (id_playlist)
ON DELETE NO ACTION
ON UPDATE NO ACTION
NOT DEFERRABLE;