-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
50 lines (45 loc) · 1.21 KB
/
Copy pathschema.sql
File metadata and controls
50 lines (45 loc) · 1.21 KB
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
-- USERS: użytkownicy platformy
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
-- MOVIES: filmy w serwisie
CREATE TABLE movies (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200),
release_year INT,
duration_minutes INT
);
-- GENRES: gatunki filmowe
CREATE TABLE genres (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50)
);
-- MOVIE_GENRES: relacja many-to-many (film ↔ gatunek)
CREATE TABLE movie_genres (
movie_id INT,
genre_id INT,
PRIMARY KEY (movie_id, genre_id),
FOREIGN KEY (movie_id) REFERENCES movies(id),
FOREIGN KEY (genre_id) REFERENCES genres(id)
);
-- RATINGS: oceny filmów
CREATE TABLE ratings (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
movie_id INT,
rating INT CHECK (rating BETWEEN 1 AND 10),
rating_date DATE,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (movie_id) REFERENCES movies(id)
);
-- WATCH HISTORY: historia oglądania
CREATE TABLE watch_history (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
movie_id INT,
watched_at DATETIME,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (movie_id) REFERENCES movies(id)
);