-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
87 lines (80 loc) · 2.1 KB
/
Copy pathsetup.sql
File metadata and controls
87 lines (80 loc) · 2.1 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
CREATE TABLE IF NOT EXISTS users (
userId VARCHAR(255) PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
accountType VARCHAR(10) CHECK (accountType IN ('Coach', 'Athlete')),
bio TEXT,
firstName VARCHAR(255),
lastName VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS user_relations(
userId VARCHAR(255) REFERENCES users(userId) NOT NULL,
relationId VARCHAR(255) REFERENCES users(userId) NOT NULL,
UNIQUE (userId, relationId)
);
CREATE TABLE IF NOT EXISTS athlete_time_inputs(
id SERIAL PRIMARY KEY,
athleteId VARCHAR(255) REFERENCES users(userId) NOT NULL,
distance INT DEFAULT 0,
time FLOAT DEFAULT 0,
date VARCHAR(10) DEFAULT CURRENT_DATE,
timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS athlete_rest_inputs(
id SERIAL PRIMARY KEY,
athleteId VARCHAR(255) REFERENCES users(userId) NOT NULL,
restTime INT DEFAULT 0,
date VARCHAR(10) DEFAULT CURRENT_DATE,
timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS athlete_note_inputs(
id SERIAL PRIMARY KEY,
athleteId VARCHAR(255) REFERENCES users(userId) NOT NULL,
note TEXT DEFAULT '',
date VARCHAR(10) DEFAULT CURRENT_DATE,
timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE OR REPLACE VIEW athlete_inputs AS
SELECT
id,
athleteId,
distance,
time,
date,
NULL AS restTime,
NULL AS note,
timeStamp,
'run' AS type
FROM athlete_time_inputs
UNION ALL
SELECT
id,
athleteId,
NULL AS distance,
NULL AS time,
date,
restTime,
NULL AS note,
timeStamp,
'rest' AS type
FROM athlete_rest_inputs
UNION ALL
SELECT
id,
athleteId,
NULL AS distance,
NULL AS time,
date,
NULL AS restTime,
note,
timeStamp,
'note' AS type
FROM athlete_note_inputs;
CREATE INDEX idx_user_relations_userid_relationid
ON user_relations (userId, relationId);
-- Addition 10/28/2025
CREATE TABLE IF NOT EXISTS context_urls(
id SERIAL PRIMARY KEY,
coachId VARCHAR(255) REFERENCES users(userId) NOT NULL,
contextUrl TEXT NOT NULL,
date TIMESTAMP DEFAULT CURRENT_DATE
);