-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.db
107 lines (92 loc) · 3.28 KB
/
schema.db
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
CREATE TABLE entries(record_id integer primary key,
date_entered text,
time_entered text,
notes text,
UNIQUE(date_entered) ON CONFLICT FAIL
);
CREATE TABLE painlevel(
record_id integer primary key,
averagepain unsigned tinyint,
maxpain unsigned tinyint,
FOREIGN KEY (record_id) REFERENCES entries(record_id)
);
CREATE TABLE painsite(
site_id integer primary key autoincrement,
location text,
active smallint default 1 NOT NULL,
UNIQUE(date_entered) ON CONFLICT FAIL
);
CREATE TABLE paindetail(record_id integer not null,
site_id integer not null,
painlevel unsigned tinyint,
PRIMARY KEY(record_id, site_id),
FOREIGN KEY(record_id) references entries(record_id),
FOREIGN KEY(site_id) references painsite(site_id)
);
CREATE TABLE symptom(symptom_id integer primary key autoincremen,
name text,
active smallint default 1 NOT NULL,
UNIQUE(name) ON CONFLICT FAIL
);
CREATE TABLE symptomdetail(record_id integer not null,
symptom_id integer not null,
intensity unsigned tinyint,
PRIMARY KEY(record_id, symptom_id),
FOREIGN KEY(record_id) references entries(record_id),
FOREIGN KEY(symptom_id) references symptom(symptom_id)
);
CREATE TABLE medication(medication_id integer primary key autoincrement,
name text not null,
unit text NOT NULL,
dosage unsigned int NOT NULL,
quantity unsigned int NOT NULL,
frequency text,
active smallint default 1 NOT NULL,
UNIQUE(name,unit,dosage) ON CONFLICT FAIL
);
CREATE TABLE medicationdetail(record_id integer not null,
medication_id integer not null,
quantity unsigned int not null,
PRIMARY KEY(record_id, medication_id),
FOREIGN KEY(record_id) references entries(record_id),
FOREIGN KEY(medication_id) references medication(medication_id)
);
CREATE TABLE treatment(treatment_id integer primary key autoincrement,
name text not null,
provider text,
frequency text,
active smallint default 1 NOT NULL,
UNIQUE(name) ON CONFLICT FAIL
);
CREATE TABLE treatmentdetail(record_id integer not null,
treatment_id integer not null,
times_per_day integer default 0 NOT NULL,
hours integer,
minutes integer,
PRIMARY KEY(record_id, treatment_id),
FOREIGN KEY(record_id) references entries(record_id),
FOREIGN KEY(treatment_id) references treatment(treatment_id)
);
CREATE TABLE activity(activity_id integer primary key autoincrement,
name text not null,
active smallint default 1 NOT NULL,
UNIQUE(name) ON CONFLICT FAIL
);
CREATE TABLE activitydetail(record_id integer not null,
activity_id integer not null,
hours integer not null,
minutes integer default(0),
intensity unsigned tinyint,
PRIMARY KEY(record_id, activity_id),
FOREIGN KEY(record_id) references entries(record_id),
FOREIGN KEY(activity_id) references activity(activity_id)
);
CREATE TABLE sleep(record_id integer PRIMARY KEY,
hours integer not null,
minutes integer default(0),
quality unsigned tinyint,
light_out_time text,
asleep_time text,
awake_time text,
FOREIGN KEY(record_id) references entries(record_id)
);