-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupDatabase.sql
More file actions
82 lines (65 loc) · 1.9 KB
/
setupDatabase.sql
File metadata and controls
82 lines (65 loc) · 1.9 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
-- lang mysql
-- Create Batteries table
CREATE TABLE Batteries (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
date DATE NOT NULL, -- Manufacture Date
manufacturer VARCHAR(25),
description VARCHAR(255) NOT NULL,
-- Test data
capacity DOUBLE,
startVoltage DOUBLE,
-- Constraints
PRIMARY KEY (id),
UNIQUE (name)
);
-- Create Tests table
CREATE TABLE Tests (
startTime BIGINT UNSIGNED NOT NULL,
batteryId INT UNSIGNED NOT NULL,
name VARCHAR(64),
-- Result data
duration BIGINT UNSIGNED NOT NULL,
startVoltage DOUBLE NOT NULL,
capacity DOUBLE NOT NULL,
success BOOLEAN NOT NULL,
codeVersion INT NOT NULL, -- Needed to understand how certain values were calculated
-- Constraints
PRIMARY KEY (startTime),
FOREIGN KEY (batteryId) REFERENCES Batteries(id)
);
-- Create Timestamps table
CREATE TABLE Timestamps (
testId BIGINT UNSIGNED NOT NULL,
time BIGINT UNSIGNED NOT NULL,
voltage DOUBLE NOT NULL,
current DOUBLE NOT NULL,
FOREIGN KEY (testId) REFERENCES Tests(startTime)
);
-- Create Notes table
CREATE TABLE Battery_Notes (
batteryId INT UNSIGNED NOT NULL,
time BIGINT UNSIGNED NOT NULL,
note VARCHAR(1023) NOT NULL,
PRIMARY KEY (batteryId, time)
);
-- Create Teams table
CREATE TABLE Teams (
teamNumber INT UNSIGNED NOT NULL,
name VARCHAR(63) NOT NULL,
PRIMARY KEY (teamNumber),
UNIQUE (name)
);
-- Create Match table
CREATE TABLE Matches (
eventKey VARCHAR(31) NOT NULL,
matchKey VARCHAR(31) NOT NULL,
batteryId INT UNSIGNED NOT NULL,
teamNumber INT UNSIGNED NOT NULL,
time BIGINT UNSIGNED,
voltageHigh DOUBLE UNSIGNED NOT NULL,
voltageLow DOUBLE UNSIGNED NOT NULL,
PRIMARY KEY (eventKey, matchKey, batteryId),
FOREIGN KEY (teamNumber) REFERENCES Teams(teamNumber),
FOREIGN KEY (batteryId) REFERENCES Batteries(id),
);