summaryrefslogtreecommitdiffstats
path: root/setup/poolctrl.sql
blob: 01314aa2c86cc439395e7348675687f99ce33f63 (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
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
CREATE DATABASE `##poolctrl##` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE ##poolctrl##;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

-- PoolCtrl Tabellen

CREATE TABLE IF NOT EXISTS `poolctrl_event` (
  `eventID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `start` timestamp COLLATE utf8_unicode_ci NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `end` timestamp COLLATE utf8_unicode_ci NULL,
  `participants` int(4) DEFAULT NULL,
  `note` varchar(140) COLLATE utf8_unicode_ci DEFAULT NULL,
  `category` int(11) NOT NULL,
  `pbs_poolID` int(11) NOT NULL,
  `pbs_membershipID` int(11) NOT NULL,
  `pbs_bootosID` int(11) NOT NULL,
  `pbs_configID` int(11) DEFAULT NULL,
  `pbs_bootmenuID` int(11) NOT NULL,
  `pbs_filterID` int(11) NOT NULL,
  `repeat` bool NOT NULL DEFAULT false,
  `repeattype` int(11) NULL,
  `repeatend` int(11) NULL,
  `repeatdate` timestamp COLLATE utf8_unicode_ci NULL,
  `repeatings` int(4) NULL,
  `immediate` bool NOT NULL DEFAULT false,
  `running` bool NOT NULL DEFAULT false,
  `runningtype` int(11) DEFAULT NULL,
  `created` varchar(14) COLLATE utf8_unicode_ci NULL,
  PRIMARY KEY (`eventID`),
  KEY `pbs_poolID` (`pbs_poolID`),
  KEY `pbs_membershipID` (`pbs_membershipID`),
  KEY `pbs_bootosID` (`pbs_bootosID`),
  KEY `pbs_configID` (`pbs_configID`),
  KEY `pbs_bootmenuID` (`pbs_bootmenuID`),
  KEY `pbs_filterID` (`pbs_filterID`),
  KEY `category` (`category`),
  KEY `runningtype` (`runningtype`),
  KEY `repeattype` (`repeattype`),
  KEY `repeatend` (`repeatend`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `poolctrl_runningtype` (
  `runningtypeID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
  PRIMARY KEY (`runningtypeID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `poolctrl_repeattype` (
  `repeattypeID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
  PRIMARY KEY (`repeattypeID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `poolctrl_repeatend` (
  `repeatendID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
  PRIMARY KEY (`repeatendID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `poolctrl_eventcategory` (
  `eventcategoryID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
  PRIMARY KEY (`eventcategoryID`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `poolctrl_eventreport` (
  `reportID` int(11) NOT NULL AUTO_INCREMENT,
  `result` varchar(140) COLLATE utf8_unicode_ci DEFAULT 'successful',
  `errors` varchar(140) COLLATE utf8_unicode_ci,
  `type` int(11) NOT NULL,
  `eventID` int(11) NOT NULL,
  `created` varchar(14) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`reportID`),
  KEY `eventID` (`eventID`),
  KEY `type` (`type`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

-- PBS2 Tabellen
-- TO DO: Tabellen an dieser Stelle nicht per Hand erzeugen sondern von der PBS2-Datenbank kopieren, sodass diese auf dem neusten Stand sind
CREATE TABLE IF NOT EXISTS `pbs_bootos` (
  `bootosID` int(11) NOT NULL AUTO_INCREMENT,
  `groupID` int(11) NOT NULL,
  `membershipID` int(11),
  `title` varchar(30) NOT NULL,
  `description` varchar(140),
  `distro` varchar(30),
  `distroversion` varchar(30),
  `source` varchar(140),
  `share` varchar(30),
  `shortname` varchar(30),
  `defaultkcl` varchar(255),
  `created` VARCHAR(14) NOT NULL,
  `expires` VARCHAR(14),
  `public` int(11) NOT NULL DEFAULT '-1',
  PRIMARY KEY (`bootosID`),
  KEY `groupID` (`groupID`),
  KEY `membershipID` (`membershipID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `pbs_config` (
  `configID` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(30) NOT NULL,
  `description` varchar(140),
  `groupID` int(11),
  `membershipID` int(11),
  `visible` tinyint(1) DEFAULT '0',
  `created` VARCHAR(14) NOT NULL,
  `bootosID` int(11) NOT NULL,
  PRIMARY KEY (`configID`),
  KEY `bootosID` (`bootosID`),
  KEY `groupID` (`groupID`),
  KEY `membershipID` (`membershipID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `pbs_pool` (
  `poolID` int(11) NOT NULL AUTO_INCREMENT,
  `groupID` int(11) NOT NULL,
  `title` varchar(30) NOT NULL,
  `description` varchar(140),
  `location` varchar(30),
  PRIMARY KEY (`poolID`),
  KEY `groupID` (`groupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `pbs_client` (
  `clientID` int(11) NOT NULL AUTO_INCREMENT,
  `groupID` int(11) NOT NULL,
  `macadress` varchar(17) NOT NULL,
  `hardwarehash` varchar(32),
  `ip` varchar(15) NOT NULL,
  `ip6` varchar(45),
  `created` int(15),
  PRIMARY KEY (`clientID`),
  KEY `groupID` (`groupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `pbs_poolentries` (
  `poolentriesID` INT NOT NULL AUTO_INCREMENT,
  `poolID` int(11) NOT NULL,
  `clientID` int(11) NOT NULL,
  PRIMARY KEY (`poolentriesID`),
  KEY `poolID` (`poolID`),
  KEY `clientID` (`clientID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

-- Constraints
ALTER TABLE `pbs_config`
  ADD CONSTRAINT `pbs_config_ibfk` FOREIGN KEY (`bootosID`) REFERENCES `pbs_bootos` (`bootosID`) ON DELETE CASCADE; 

ALTER TABLE `pbs_poolentries`
  ADD CONSTRAINT `pbs_poolentries_ibfk_1` FOREIGN KEY (`poolID`) REFERENCES `pbs_pool` (`poolID`) ON DELETE CASCADE,
  ADD CONSTRAINT `pbs_poolentries_ibfk_2` FOREIGN KEY (`clientID`) REFERENCES `pbs_client` (`clientID`) ON DELETE CASCADE;

ALTER TABLE `poolctrl_eventreport`
  ADD CONSTRAINT `pbs_eventreport_eventidC` FOREIGN KEY (`eventID`) REFERENCES `poolctrl_event` (`eventID`) ON DELETE CASCADE,
  ADD CONSTRAINT `pbs_eventreport_typeidC` FOREIGN KEY (`type`) REFERENCES `poolctrl_runningtype` (`runningtypeID`) ON DELETE CASCADE;

ALTER TABLE `poolctrl_event`
  ADD CONSTRAINT `poolctrl_event_categoryC` FOREIGN KEY (`category`) REFERENCES `poolctrl_eventcategory` (`eventcategoryID`) ON DELETE CASCADE,
  ADD CONSTRAINT `poolctrl_event_repeattypeC` FOREIGN KEY (`repeattype`) REFERENCES `poolctrl_repeattype` (`repeattypeID`) ON DELETE SET NULL,
  ADD CONSTRAINT `poolctrl_event_runningtypeC` FOREIGN KEY (`runningtype`) REFERENCES `poolctrl_runningtype` (`runningtypeID`) ON DELETE SET NULL,
  ADD CONSTRAINT `poolctrl_event_repeatendC` FOREIGN KEY (`repeatend`) REFERENCES `poolctrl_repeatend` (`repeatendID`) ON DELETE SET NULL,
  ADD CONSTRAINT `poolctrl_event_startC` CHECK (start > CURRENT_TIMESTAMP()),
  ADD CONSTRAINT `poolctrl_event_endC` CHECK (end > start);

-- Adding eventcategories
INSERT INTO `poolctrl_eventcategory` (`eventcategoryID`, `title`) VALUES
(1, 'Lecture'),
(2, 'Maintenance'),
(3, 'Boot'),
(4, 'Shutdown');

-- Adding runningtypes
INSERT INTO `poolctrl_runningtype` (`runningtypeID`, `title`) VALUES
(1, 'Boot'),
(2, 'Shutdown');

-- Adding repeattypes
INSERT INTO `poolctrl_repeattype` (`repeattypeID`, `title`) VALUES
(1, 'Daily'),
(2, 'Once a week'),
(3, 'Every couple of weeks'),
(4, 'Every month');

-- Adding repeatend
INSERT INTO `poolctrl_repeatend` (`repeatendID`, `title`) VALUES
(1, 'After'),
(2, 'Date');