Subversion Repositories computer_asset_manager_v2

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 rodolico 1
/* this is superceded by camp_to_camp2.sql, but kept here for reference */
2
 
3
 
3 rodolico 4
/* 
5
order is very important here. We should load child tables first
6
then we can load the main tables. By using more complex joins,
7
we can get the data in the right place
8
*/
9
 
10
/* import users */
11
insert into _user (_user_id,name,passwd,email,added_date,removed_date)
12
   select login_id,email,pass,null,added_date,removed_date from camp.login;
13
/* and _system */
14
insert into _system select _system_id,group_name,key_name,theValue from camp._system;
15
/* 
16
   create an entry for the user sysinfo will use to insert values
17
   this will also be the user we use for all inserts here
18
*/
19
insert into _system  select null,'sysinfo','_user_id',_user_id from _user where _user.name = 'Admin';
20
 
21
/* set up device_type */
22
insert into device_type select device_type_id,name,(show_as_system='Y') from camp.device_type;
23
 
24
/* now, set up category and attribute tables */
25
/* create some basic categories */
26
insert into category (category_id,name) values ( null,'Device');
27
insert into category (category_id,name) values (null,'Location' );
28
insert into category (category_id,name) values (null,'Client' );
29
insert into attribute( attribute_id,name,report_name,category_id) 
30
   select 
31
      camp.attrib.attrib_id,
32
      camp.attrib.name,
33
      camp.attrib.keyname,
34
      category.category_id
35
   from 
36
      camp.attrib 
37
      join camp2.category 
38
   where 
39
      camp2.category.name = 'Device';
40
/* Notes can be used for any category, so we set for all of them */
41
insert into attribute (attribute_id,name,report_name,category_id)
42
   select null,'Notes',null,category.category_id from category;
43
 
44
/* ok, all done with child tables, let's load the three main tables */
45
 
46
/* first, I want a temporary view into device that only lists systems */
47
create or replace view v_temp_system as 
48
   select camp.device.* 
49
   from camp.device join camp.device_type using (device_type_id) 
50
   where device_type.show_as_system = 'Y';
51
 
52
insert into client (client_id,name,_user_id,added_date,removed_date)
53
   select 
54
      client_id,
55
      name,
56
      _system.key_value,
57
      added_date,
58
      removed_date
59
   from
60
      camp.client 
61
      join _system 
62
   where 
63
      _system.group_name = 'sysinfo' 
64
      and _system.key_name='_user_id';
65
 
66
insert into location (location_id,name,_user_id,added_date,removed_date)
67
   select
68
      site_id,
69
      name,
70
      _system.key_value,
71
      added_date,
72
      removed_date
73
   from
74
      camp.site
75
      join _system 
76
   where 
77
      _system.group_name = 'sysinfo' 
78
      and _system.key_name='_user_id';
79
 
80
insert into device (device_id,name,device_type_id,_user_id,added_date,removed_date) 
81
   select 
82
      v_temp_system.device_id,
83
      v_temp_system.name,
84
      v_temp_system.device_type_id,
85
      _system.key_value,
86
      v_temp_system.added_date,
87
      v_temp_system.removed_date
88
   from 
89
      v_temp_system
90
      join _system 
91
   where 
92
      _system.group_name = 'sysinfo' 
93
      and _system.key_name='_user_id';
94
 
95
 
96
/* Add notes to the above tables */
97
insert into location_attribute (location_attribute_id,location_id,attribute_id,report_value,_user_id,added_date,removed_date )
98
   select
99
      null,
100
      camp.site.site_id,
101
      attribute.attribute_id,
102
      camp.site.notes,
103
      _system.key_value,
104
      now(),
105
      null
106
   from
107
      camp.site 
108
      join attribute 
109
      join category using (category_id) 
110
      join _system 
111
   where
112
      camp.site.notes is not null 
113
      and _system.group_name = 'sysinfo' 
114
      and _system.key_name='_user_id'
115
      and length(camp.site.notes) > 0
116
      and category.name = 'Location' 
117
      and attribute.name = 'Notes';
118
 
119
insert into client_attribute (client_attribute_id,client_id,attribute_id,report_value,_user_id,added_date,removed_date )
120
   select
121
      null,
122
      camp.client.client_id,
123
      attribute.attribute_id,
124
      camp.client.notes,
125
      _system.key_value,
126
      now(),
127
      null
128
   from
129
      camp.client
130
      join attribute 
131
      join category using (category_id) 
132
      join _system 
133
   where
134
      camp.client.notes is not null 
135
      and _system.group_name = 'sysinfo' 
136
      and _system.key_name='_user_id'
137
      and length(camp.client.notes) > 0
138
      and category.name = 'Client' 
139
      and attribute.name = 'Notes';
140
 
141
 
142
insert into device_attribute (device_attribute_id,device_id,attribute_id,report_value,_user_id,added_date,removed_date )
143
   select
144
      null,
145
      v_temp_system.device_id,
146
      attribute.attribute_id,
147
      v_temp_system.notes,
148
      _system.key_value,
149
      now(),
150
      null
151
   from
152
      v_temp_system
153
      join attribute 
154
      join category using (category_id) 
155
      join _system 
156
   where
157
      v_temp_system.notes is not null 
158
      and _system.group_name = 'sysinfo' 
159
      and _system.key_name='_user_id'
160
      and length(v_temp_system.notes) > 0
161
      and category.name = 'Device' 
162
      and attribute.name = 'Notes';
163
 
164
/* at this point, we need to do the links between device, location and client */
165
 
166
insert into device_location ( device_location_id,device_id,location_id,_user_id,added_date,removed_date)
167
   select 
168
      null,
169
      v_temp_system.device_id,
170
      camp.site.site_id,
171
      _system.key_value,
172
      camp.site.added_date,
173
      camp.site.removed_date
174
   from v_temp_system
175
      join camp.site using (site_id)
176
      join _system
177
   where 
178
      _system.group_name = 'sysinfo' 
179
      and _system.key_name='_user_id';
180
 
181
 
182
insert into device_client ( device_client_id,device_id,client_id,_user_id,added_date,removed_date)
183
   select 
184
      null,
185
      v_temp_system.device_id,
186
      camp.client.client_id,
187
      _system.key_value,
188
      camp.client.added_date,
189
      camp.client.removed_date
190
   from v_temp_system
191
      join camp.site using (site_id)
192
      join camp.client using (client_id)
193
      join _system
194
   where 
195
      _system.group_name = 'sysinfo' 
196
      and _system.key_name='_user_id';
197
 
198
insert into location_client( location_client_id,location_id,client_id,_user_id,added_date,removed_date )
199
   select 
200
      null,
201
      camp.site.site_id,
202
      camp.client.client_id,
203
      _system.key_value,
204
      camp.site.added_date,
205
      camp.site.removed_date
206
   from 
207
      camp.site
208
      join camp.client using (client_id)
209
      join _system
210
   where 
211
      _system.group_name = 'sysinfo' 
212
      and _system.key_name='_user_id';
213
 
214
 
215
/* maintenance module */
216
insert into maintenance_task (maintenance_task_id,name,description,default_period )
217
   select 
218
      maintenance_task_id,
219
      description,
220
      notes,
221
      default_period
222
   from camp.maintenance_task;
223
 
224
insert into maintenance_schedule (maintenance_schedule_id,device_id,maintenance_task_id,schedule,_user_id,added_date,removed_date)
225
   select
226
      maintenance_schedule_id,
227
      device_id,
228
      maintenance_task_id,
229
      schedule,
230
      login_id,
231
      added_date,
232
      removed_date
233
   from
234
      camp.maintenance_schedule;
235
 
236
insert into maintenance_performed (maintenance_performed_id,device_id,maintenance_task_id,date_performed,_user_id,notes )
237
   select 
238
      maintenance_performed_id,
239
      device_id,
240
      maintenance_task_id,
241
      maintenance_date,
242
      login_id,
243
      notes
244
   from 
245
      camp.maintenance_performed;
246
 
247
insert into maintenance_group values (null,'Windows Server',null,now());
248
insert into maintenance_group values (null,'Linux Server',null,now());
249
insert into maintenance_group values (null,'Redhat Server',null,now());
250
insert into maintenance_group values (null,'Debian Server',null,now());
251
insert into maintenance_group values (null,'Xen DOM0',null,now());
252
insert into maintenance_group values (null,'Windows Workstation',null,now());
253
insert into maintenance_group values (null,'Linux Server',null,now());
254
insert into maintenance_group values (null,'IPFire Router',null,now());
255
insert into maintenance_group values (null,'Physical Device',null,now());
256
 
257
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
258
   select 
259
      maintenance_task_id,
260
      maintenance_group_id,
261
      default_period
262
   from
263
      maintenance_task,
264
      maintenance_group
265
   where
266
      maintenance_group.name = 'Windows Server'
267
      and maintenance_task_id in ( 3,4,16,14,15);
268
 
269
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
270
   select 
271
      maintenance_task_id,
272
      maintenance_group_id,
273
      90
274
   from
275
      maintenance_task,
276
      maintenance_group
277
   where
278
      maintenance_group.name = 'Windows Server'
279
      and maintenance_task_id in ( 16 );
280
 
281
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
282
   select 
283
      maintenance_task_id,
284
      maintenance_group_id,
285
      30
286
   from
287
      maintenance_task,
288
      maintenance_group
289
   where
290
      maintenance_group.name = 'Linux Server'
291
      and maintenance_task_id in ( 4,5 );
292
 
293
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
294
   select 
295
      maintenance_task_id,
296
      maintenance_group_id,
297
      7
298
   from
299
      maintenance_task,
300
      maintenance_group
301
   where
302
      maintenance_group.name = 'Debian Server'
303
      and maintenance_task_id in ( 1,4,5 );
304
 
305
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
306
   select 
307
      maintenance_task_id,
308
      maintenance_group_id,
309
      7
310
   from
311
      maintenance_task,
312
      maintenance_group
313
   where
314
      maintenance_group.name = 'Redhat Server'
315
      and maintenance_task_id in ( 2,4,5 );
316
 
317
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
318
   select 
319
      maintenance_task_id,
320
      maintenance_group_id,
321
      180
322
   from
323
      maintenance_task,
324
      maintenance_group
325
   where
326
      maintenance_group.name = 'Xen DOM0'
327
      and maintenance_task_id in ( 1,4,5,14 );
328
 
329
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
330
   select 
331
      maintenance_task_id,
332
      maintenance_group_id,
333
      30
334
   from
335
      maintenance_task,
336
      maintenance_group
337
   where
338
      maintenance_group.name = 'Windows Server'
339
      and maintenance_task_id in ( 3,4,16,14,15);
340
 
341
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
342
   select 
343
      maintenance_task_id,
344
      maintenance_group_id,
345
      180
346
   from
347
      maintenance_task,
348
      maintenance_group
349
   where
350
      maintenance_group.name = 'Physical Device'
351
      and maintenance_task_id in ( 6,7 );
352
 
353
insert into maintenance_group_task (maintenance_task_id,maintenance_group_id,default_period)
354
   select 
355
      maintenance_task_id,
356
      maintenance_group_id,
357
      30
358
   from
359
      maintenance_task,
360
      maintenance_group
361
   where
362
      maintenance_group.name = 'IPFire Router'
363
      and maintenance_task_id in ( 1,4,5,14 );
364
 
365
select
366
   maintenance_group.name,
367
   maintenance_task.name,
368
   maintenance_group_task.default_period
369
from
370
   maintenance_group 
371
   join maintenance_group_task using (maintenance_group_id) 
372
   join maintenance_task using (maintenance_task_id) 
373
order by
374
   maintenance_group.name;
375
 
376