-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
67 lines (59 loc) · 1.69 KB
/
init.sql
File metadata and controls
67 lines (59 loc) · 1.69 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- Drop the tables if they exist
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS players;
DROP TABLE IF EXISTS teams;
DROP TABLE IF EXISTS team_players;
DROP TABLE IF EXISTS tournaments;
DROP TABLE IF EXISTS tournament_teams;
DROP TABLE IF EXISTS tournament_players;
-- Create the users table
CREATE TABLE users (
id INTEGER PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
password TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone TEXT UNIQUE
);
-- Create the players table
CREATE TABLE players (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Create the teams table
CREATE TABLE teams (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
-- Create the team_players table
CREATE TABLE team_players (
id INTEGER PRIMARY KEY,
team_id INTEGER NOT NULL,
player_id INTEGER NOT NULL,
FOREIGN KEY (team_id) REFERENCES teams(id),
FOREIGN KEY (player_id) REFERENCES players(id)
);
-- Create the tournaments table
CREATE TABLE tournaments (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
start_date TEXT NOT NULL,
end_date TEXT NOT NULL
);
-- Create the tournament_teams table
CREATE TABLE tournament_teams (
id INTEGER PRIMARY KEY,
tournament_id INTEGER NOT NULL,
team_id INTEGER NOT NULL,
FOREIGN KEY (tournament_id) REFERENCES tournaments(id),
FOREIGN KEY (team_id) REFERENCES teams(id)
);
-- Create the tournament_players table
CREATE TABLE tournament_players (
id INTEGER PRIMARY KEY,
tournament_id INTEGER NOT NULL,
player_id INTEGER NOT NULL,
FOREIGN KEY (tournament_id) REFERENCES tournaments(id),
FOREIGN KEY (player_id) REFERENCES players(id)
);