This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
schema.sql
executable file
·260 lines (224 loc) · 7.55 KB
/
schema.sql
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
-- for Postgres change int NOT NULL AUTO_INCREMENT to serial
-- for MySQL
SET storage_engine=INNODB;
drop table if exists stats_by_genome;
drop table if exists stats_by_variant;
drop table if exists goal;
drop table if exists pageview;
drop table if exists genome_variant_link;
drop table if exists variant;
drop table if exists gene;
drop table if exists genome;
drop table if exists referrer;
drop table if exists error;
drop table if exists visitor;
drop table if exists page;
drop table if exists domain;
--
-- Table structure for table domain
--
CREATE TABLE domain (
domain_id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
PRIMARY KEY (domain_id),
UNIQUE (name)
);
--
-- Table structure for table error
--
CREATE TABLE error (
error_id int NOT NULL AUTO_INCREMENT,
page_id int NOT NULL,
visitor_id int NOT NULL,
message varchar(255) NOT NULL,
line_number int NOT NULL,
timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (error_id)
);
CREATE INDEX page_id_error ON error (page_id);
CREATE INDEX visitor_id_error ON error (visitor_id);
--
-- Table structure for table gene
--
CREATE TABLE gene (
gene_id int NOT NULL AUTO_INCREMENT,
page_id int NOT NULL,
name varchar(255),
PRIMARY KEY (gene_id),
UNIQUE (page_id,name)
);
--
-- Table structure for table genome
--
CREATE TABLE genome (
genome_id int NOT NULL AUTO_INCREMENT,
page_id int NOT NULL,
hash varchar(255) NOT NULL,
PRIMARY KEY (genome_id),
UNIQUE (page_id,hash)
);
--
-- Table structure for table genome_variant_link
--
CREATE TABLE genome_variant_link (
genome_variant_link_id int NOT NULL AUTO_INCREMENT,
genome_id int NOT NULL,
variant_id int NOT NULL,
PRIMARY KEY (genome_variant_link_id),
UNIQUE (genome_id,variant_id)
);
--
-- Table structure for table goal
--
CREATE TABLE goal (
goal_id int NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
value int NOT NULL,
pageview_xid bigint NOT NULL,
PRIMARY KEY (goal_id)
);
CREATE INDEX pageview_xid_goal ON goal (pageview_xid);
--
-- Table structure for table page
--
CREATE TABLE page (
page_id int NOT NULL AUTO_INCREMENT,
domain_id int NOT NULL,
name varchar(255),
PRIMARY KEY (page_id),
UNIQUE (domain_id,name)
);
--
-- Table structure for table pageview
--
CREATE TABLE pageview (
pageview_id int NOT NULL AUTO_INCREMENT,
pageview_xid bigint NOT NULL,
page_id int NOT NULL,
visitor_id int NOT NULL,
referrer_id int default NULL,
genome_id int NOT NULL,
vary_call varchar(255),
load_time int NOT NULL,
init_time int NOT NULL,
results_time int,
idle_time int,
vary_time int,
timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (pageview_id),
UNIQUE (pageview_xid)
);
CREATE INDEX page_id_pageview ON pageview (page_id);
CREATE INDEX visitor_id_pageview ON pageview (visitor_id);
CREATE INDEX referrer_id_pageview ON pageview (referrer_id);
CREATE INDEX genome_id_pageview ON pageview (genome_id);
-- Table structure for table referrer
--
CREATE TABLE referrer (
referrer_id int NOT NULL AUTO_INCREMENT,
hash varchar(255) NOT NULL,
domain varchar(255) NOT NULL,
path varchar(255) NOT NULL,
external varchar(255) NOT NULL,
search_engine varchar(255) NOT NULL,
search_term varchar(255) NOT NULL,
PRIMARY KEY (referrer_id),
UNIQUE (hash)
);
-- external varchar NOT NULL CHECK(external IN('true','false')) ,
--
-- Table structure for table variant
--
CREATE TABLE variant (
variant_id int NOT NULL AUTO_INCREMENT,
gene_id int NOT NULL,
name varchar(255),
PRIMARY KEY (variant_id),
UNIQUE (gene_id,name)
);
--
-- Table structure for table stats_by_variant
--
CREATE TABLE stats_by_variant (
variant_id int NOT NULL,
count int,
nonzero int,
sum int,
avg double precision,
sumsq bigint,
wavg double precision,
UNIQUE (variant_id)
);
--
-- Table structure for table stats_by_genome
--
CREATE TABLE stats_by_genome (
genome_id int NOT NULL,
count int,
nonzero int,
sum int,
avg double precision,
sumsq bigint,
wavg double precision,
UNIQUE (genome_id)
);
--
-- Table structure for table visitor
--
CREATE TABLE visitor (
visitor_id int NOT NULL AUTO_INCREMENT,
hash varchar(255) NOT NULL,
ip_address varchar(255) NOT NULL,
Parent varchar(255) NOT NULL,
Platform varchar(255) NOT NULL,
Browser varchar(255) NOT NULL,
Version varchar(255) NOT NULL,
MajorVer varchar(255) NOT NULL,
Frames varchar(255) NOT NULL,
IFrames varchar(255) NOT NULL,
Tables varchar(255) NOT NULL,
Cookies varchar(255) NOT NULL,
JavaApplets varchar(255) NOT NULL,
JavaScript varchar(255) NOT NULL,
CSS varchar(255) NOT NULL,
CssVersion varchar(255) NOT NULL,
supportsCSS varchar(255) NOT NULL,
MinorVer varchar(255) NOT NULL,
Alpha varchar(255) NOT NULL,
Beta varchar(255) NOT NULL,
Win16 varchar(255) NOT NULL,
Win32 varchar(255) NOT NULL,
Win64 varchar(255) NOT NULL,
BackgroundSounds varchar(255) NOT NULL,
AuthenticodeUpdate varchar(255) NOT NULL,
CDF varchar(255) NOT NULL,
VBScript varchar(255) NOT NULL,
ActiveXControls varchar(255) NOT NULL,
Stripper varchar(255) NOT NULL,
isBanned varchar(255) NOT NULL,
WAP varchar(255) NOT NULL,
isMobileDevice varchar(255) NOT NULL,
isSyndicationReader varchar(255) NOT NULL,
Crawler varchar(255) NOT NULL,
AOL varchar(255) NOT NULL,
aolVersion varchar(255) NOT NULL,
netCLR varchar(255) NOT NULL,
ClrVersion varchar(255) NOT NULL,
PRIMARY KEY (visitor_id),
UNIQUE (hash)
);
ALTER TABLE variant ADD CONSTRAINT variant_ibfk_2 FOREIGN KEY (gene_id) REFERENCES gene (gene_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE page ADD CONSTRAINT page_ibfk_1 FOREIGN KEY (domain_id) REFERENCES domain (domain_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE genome_variant_link ADD CONSTRAINT genome_variant_link_ibfk_1 FOREIGN KEY (variant_id) REFERENCES variant (variant_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE genome_variant_link ADD CONSTRAINT genome_variant_link_ibfk_2 FOREIGN KEY (genome_id) REFERENCES genome (genome_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE genome ADD CONSTRAINT genome_ibfk_1 FOREIGN KEY (page_id) REFERENCES page (page_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE gene ADD CONSTRAINT gene_ibfk_1 FOREIGN KEY (page_id) REFERENCES page (page_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE error ADD CONSTRAINT error_ibfk_1 FOREIGN KEY (page_id) REFERENCES page (page_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE error ADD CONSTRAINT error_ibfk_2 FOREIGN KEY (visitor_id) REFERENCES visitor (visitor_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE pageview ADD CONSTRAINT pageview_ibfk_1 FOREIGN KEY (visitor_id) REFERENCES visitor (visitor_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE pageview ADD CONSTRAINT pageview_ibfk_2 FOREIGN KEY (referrer_id) REFERENCES referrer (referrer_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE pageview ADD CONSTRAINT pageview_ibfk_3 FOREIGN KEY (page_id) REFERENCES page (page_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE pageview ADD CONSTRAINT pageview_ibfk_4 FOREIGN KEY (genome_id) REFERENCES genome (genome_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE goal ADD CONSTRAINT goal_ibfk_1 FOREIGN KEY (pageview_xid) REFERENCES pageview (pageview_xid) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE stats_by_variant ADD CONSTRAINT stats_by_variant_ibfk_1 FOREIGN KEY (variant_id) REFERENCES variant (variant_id) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE stats_by_genome ADD CONSTRAINT stats_by_genome_ibfk_1 FOREIGN KEY (genome_id) REFERENCES genome (genome_id) ON DELETE CASCADE ON UPDATE CASCADE;