-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_db.sql
191 lines (156 loc) · 5.08 KB
/
create_db.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
-- This script was generated by the ERD tool in pgAdmin 4.
-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE IF NOT EXISTS public.actor
(
id_actor integer NOT NULL,
nombre character varying COLLATE pg_catalog."default",
CONSTRAINT actor_pkey PRIMARY KEY (id_actor)
);
CREATE TABLE IF NOT EXISTS public.cast_
(
id_cast integer NOT NULL,
"cast" character varying COLLATE pg_catalog."default",
CONSTRAINT cast__pkey PRIMARY KEY (id_cast)
);
CREATE TABLE IF NOT EXISTS public.cast_actor
(
id_cast_actor integer NOT NULL,
id_cast integer,
id_actor integer,
CONSTRAINT cast_actor_pkey PRIMARY KEY (id_cast_actor)
);
CREATE TABLE IF NOT EXISTS public.category
(
id_category integer NOT NULL,
type character varying COLLATE pg_catalog."default",
CONSTRAINT type_pkey PRIMARY KEY (id_category)
);
CREATE TABLE IF NOT EXISTS public.country
(
id_country integer NOT NULL,
country character varying COLLATE pg_catalog."default",
CONSTRAINT country_pkey PRIMARY KEY (id_country)
);
CREATE TABLE IF NOT EXISTS public.director
(
id_director integer NOT NULL,
director character varying COLLATE pg_catalog."default",
CONSTRAINT director_pkey PRIMARY KEY (id_director)
);
CREATE TABLE IF NOT EXISTS public.gender
(
id_gender integer NOT NULL,
listed_in character varying COLLATE pg_catalog."default",
CONSTRAINT gender_pkey PRIMARY KEY (id_gender)
);
CREATE TABLE IF NOT EXISTS public.platform
(
id_platform integer NOT NULL,
plataforma character varying COLLATE pg_catalog."default",
CONSTRAINT platform_pkey PRIMARY KEY (id_platform)
);
CREATE TABLE IF NOT EXISTS public.program
(
id_program integer NOT NULL,
id_show character varying COLLATE pg_catalog."default",
id_category integer,
title character varying COLLATE pg_catalog."default",
id_director integer,
id_cast integer,
id_country integer,
date_added date,
date_released date,
id_rating integer,
id_gender integer,
id_platform integer,
duration_int integer,
duration_type character varying,
CONSTRAINT program_pkey PRIMARY KEY (id_program)
);
CREATE TABLE IF NOT EXISTS public.rating
(
id_rating integer NOT NULL,
rating character varying COLLATE pg_catalog."default",
CONSTRAINT rating_pkey PRIMARY KEY (id_rating)
);
CREATE TABLE IF NOT EXISTS public.director_name_dir
(
id_director_name_dir integer,
id_director integer,
id_name_dir integer,
PRIMARY KEY (id_director_name_dir)
);
CREATE TABLE IF NOT EXISTS public.name_dir
(
id_name_dir integer,
"Nombre" character varying[],
PRIMARY KEY (id_name_dir)
);
ALTER TABLE IF EXISTS public.cast_actor
ADD CONSTRAINT cast_actor_id_actor_fkey FOREIGN KEY (id_actor)
REFERENCES public.actor (id_actor) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.cast_actor
ADD CONSTRAINT cast_actor_id_cast_fkey FOREIGN KEY (id_cast)
REFERENCES public.cast_ (id_cast) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_cast_fkey FOREIGN KEY (id_cast)
REFERENCES public.cast_ (id_cast) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_country_fkey FOREIGN KEY (id_country)
REFERENCES public.country (id_country) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_director_fkey FOREIGN KEY (id_director)
REFERENCES public.director (id_director) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_gender_fkey FOREIGN KEY (id_gender)
REFERENCES public.gender (id_gender) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_platform_fkey FOREIGN KEY (id_platform)
REFERENCES public.platform (id_platform) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_rating_fkey FOREIGN KEY (id_rating)
REFERENCES public.rating (id_rating) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.program
ADD CONSTRAINT program_id_type_fkey FOREIGN KEY (id_category)
REFERENCES public.category (id_category) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.director_name_dir
ADD FOREIGN KEY (id_director)
REFERENCES public.director (id_director) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.director_name_dir
ADD FOREIGN KEY (id_name_dir)
REFERENCES public.name_dir (id_name_dir) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
END;