summaryrefslogtreecommitdiffstats
path: root/db_structure.sql
blob: a47b5c1ffc39877504907565dabc3656a09cd52e (plain) (blame)
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
CREATE TABLE dozmod (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  vms_total bigint(20) NOT NULL,
  vms_new bigint(20) NOT NULL,
  vms_updated bigint(20) NOT NULL,
  vms_valid bigint(20) NOT NULL,
  lectures_total bigint(20) NOT NULL,
  lectures_new bigint(20) NOT NULL,
  lectures_updated bigint(20) NOT NULL,
  lectures_valid bigint(20) NOT NULL,
  users_total bigint(20) NOT NULL,
  users_organizations bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE machine (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  property varchar(30) COLLATE utf8_bin NOT NULL,
  value varchar(200) COLLATE utf8_bin NOT NULL,
  count bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE perLocation (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  locationname varchar(40) COLLATE utf8_bin NOT NULL,
  totalTime bigint(20) NOT NULL,
  totalOffTime bigint(20) NOT NULL,
  totalSessionTime bigint(20) NOT NULL,
  totalStandbyTime bigint(20) NOT NULL,
  longSessions bigint(20) NOT NULL,
  shortSessions bigint(20) NOT NULL,
  totalIdleTime bigint(20) NOT NULL,
  medianSessionLength bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE perVM (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  vm varchar(40) COLLATE utf8_bin NOT NULL,
  sessions bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE reports (
  id bigint(20) NOT NULL,
  date date NOT NULL,
  ip varchar(20) COLLATE utf8_bin NOT NULL,
  version varchar(200) COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE names (
  ip varchar(20) COLLATE utf8_bin NOT NULL,
  name varchar(200) COLLATE utf8_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE server (
  report bigint(20) NOT NULL,
  cpuCount bigint(20) NOT NULL,
  cpuModel varchar(200) COLLATE utf8_bin NOT NULL,
  uptime bigint(20) NOT NULL,
  memTotal bigint(20) NOT NULL,
  memFree bigint(20) NOT NULL,
  swapTotal bigint(20) NOT NULL,
  swapUsed bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE timeframe (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  tsFrom datetime NOT NULL,
  tsTo datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE total (
  report bigint(20) NOT NULL,
  days bigint(20) NOT NULL,
  totalTime bigint(20) NOT NULL,
  totalOffTime bigint(20) NOT NULL,
  totalSessionTime bigint(20) NOT NULL,
  totalStandbyTime bigint(20) NOT NULL,
  longSessions bigint(20) NOT NULL,
  shortSessions bigint(20) NOT NULL,
  totalIdleTime bigint(20) NOT NULL,
  medianSessionLength bigint(20) NOT NULL,
  uniqueUsers bigint(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE VIEW reports_newest AS
	SELECT r.id AS id, r.date AS date, r.ip AS ip, r.version AS version
	FROM (
		reports r
		JOIN (
			SELECT reports.ip AS ip, max(reports.date) AS date
			FROM reports
			GROUP BY reports.ip
		) rm
		ON (((r.ip = rm.ip) and (r.date = rm.date)))
	);

ALTER TABLE dozmod
  ADD PRIMARY KEY (report,days);

ALTER TABLE machine
  ADD PRIMARY KEY (report,days,property,value);

ALTER TABLE perLocation
  ADD PRIMARY KEY (report,days,locationname);

ALTER TABLE perVM
  ADD PRIMARY KEY (report,days,vm);

ALTER TABLE reports
  ADD PRIMARY KEY (id),
  ADD UNIQUE KEY date_ip (date,ip) USING BTREE;

ALTER TABLE server
  ADD PRIMARY KEY (report);

ALTER TABLE names
  ADD PRIMARY KEY (ip);

ALTER TABLE timeframe
  ADD PRIMARY KEY (report,days);

ALTER TABLE total
  ADD PRIMARY KEY (report,days);

ALTER TABLE reports
  MODIFY id bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE dozmod
  ADD CONSTRAINT dozmod_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE machine
  ADD CONSTRAINT machine_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE perLocation
  ADD CONSTRAINT perLocation_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE perVM
  ADD CONSTRAINT perVM_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE server
  ADD CONSTRAINT server_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE timeframe
  ADD CONSTRAINT timeframe_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE total
  ADD CONSTRAINT total_report_id FOREIGN KEY (report) REFERENCES reports (id) ON DELETE CASCADE ON UPDATE CASCADE;