Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 rodolico 1
/*
2
   copy camp data to camp2 database
3
   Note: we have removed_date set to null so we don't copy anything
4
   that is old
5
*/
6
 
7
/*
8
 
9
Monster table of client, site, device and device_type
10
 
11
*/
12
 
13
drop table if exists temp;
14
create table temp as 
15
select 
16
   camp.device.device_id old_device_id,
17
   camp.device.name device_name,
18
   camp.device.serial device_serial,
19
   camp.device.part_of,
20
   date( camp.device.added_date ) device_added,
21
   date( camp.device.removed_date ) device_removed,
22
   camp.device_type.name device_type,
23
   if( camp.device_type.show_as_system = 'Y', true, false ) show_as_system,
24
   camp.site.site_id old_site_id,
25
   camp.site.name site_name,
26
   camp.client.name site_owner,
27
   date( camp.site.added_date ) site_added,
28
   date( camp.site.removed_date ) site_removed,
29
   camp.client.client_id old_client_id,
30
   camp.client.name client_name,
31
   date(camp.client.added_date) client_added,
32
   date( camp.client.removed_date ) client_removed
33
from
34
   camp.device
35
   join camp.site using (site_id)
36
   join camp.client using (client_id)
37
   join camp.device_type using (device_type_id)
38
where
39
   device_type.show_as_system = 'Y'
40
   and device.removed_date is null
41
   and site.removed_date is null
42
   and client.removed_date is null
43
;
44
 
45
/*
46
   in the old system, there was no deliniation between site and client, so we created new 'sites' with 'NOC' at the end
47
   so we could have ownership and locations. So, fivestar equipment located at the NOC would have been put at the fictitious
48
   site 'fivestar NOC'. Modified original data so every NOC location has NOC in the name.
49
   Following query puts them all in 'Colocation NOC' (Daily Data's site) without losing ownership information
50
*/
51
 
52
update temp a
53
   join temp b
54
set
55
   a.old_site_id = b.old_site_id,
56
   a.site_name = b.site_name,
57
   a.site_added = b.site_added,
58
   a.site_owner = b.site_owner
59
where
60
   b.site_name = 'Colocation NOC'
61
   and a.site_name like '%NOC%' and a.site_name <> 'Colocation NOC';
62
 
63
 
64
/* we have some stuff at Lori Bryant's office also */
65
update temp a
66
   join temp b
67
set
68
   a.old_site_id = b.old_site_id,
69
   a.site_name = b.site_name,
70
   a.site_added = b.site_added,
71
   a.site_owner = b.site_owner
72
where
73
   b.site_name = 'Stemmons Towers'
74
   and a.site_name like 'Lori Bryant''s Office';
75
 
76
/* and Lakewood Title */
77
update temp a
78
   join temp b
79
set
80
   a.old_site_id = b.old_site_id,
81
   a.site_name = b.site_name,
82
   a.site_added = b.site_added,
83
   a.site_owner = b.site_owner
84
where
85
   b.site_name = 'Matilda and Prospect'
86
   and a.site_name like 'Lakewood Title Office';
87
 
88
/* populate client table */
89
truncate table client;
90
insert into client( name,created, removed)
91
   select distinct
92
      client_name,
93
      client_added,
94
      client_removed
95
   from temp;
96
 
97
/* populate site */
98
truncate table site;
99
insert into site( name,created,removed) 
100
   select distinct 
101
      site_name,
102
      site_added,
103
      site_removed
104
   from 
105
      temp;
106
 
107
/* get device_type directly from camp, but ignore anything not set as show_as_system */
108
truncate table device_type;
109
insert into device_type (name,show_as_system, created, removed)
110
select 
111
   name,
112
   true,
113
   date( added_date ),
114
   date( removed_date )
115
from
116
   camp.device_type
117
where
118
   show_as_system = 'Y';
119
 
120
/* Now, we're ready to get some devices */
121
truncate table device;
122
insert into device( uuid,serial,name,device_type_id,created,removed)
123
   select 
124
      null,
125
      device_serial,
126
      device_name,
127
      device_type_id,
128
      device_added,
129
      device_removed
130
   from
131
      temp
132
      join device_type on ( temp.device_type = device_type.name )
133
   ;
134
 
135
/* link a client owner to a site */
136
truncate table client_site;
137
insert into client_site ( client_id,site_id,created, removed )
138
   select 
139
      client.client_id,
140
      site.site_id,
141
      oldTable.site_added,
142
      oldTable.site_removed
143
   from 
144
      ( 
145
         select distinct 
146
            site_name,
147
            site_owner,
148
            site_added, 
149
            site_removed 
150
         from temp 
151
         ) oldTable
152
      join client on ( client.name = oldTable.site_owner )
153
      join site on ( site.name = oldTable.site_name );
154
 
155
 
156
/* verify linkage with 
157
   select client.name,site.name from client join client_site using ( client_id ) join site using (site_id );
158
*/
159
 
160
/* link a client owner to a device */
161
truncate table client_device;
162
insert into client_device ( client_id,device_id,created, removed )
163
   select 
164
      client.client_id,
165
      device.device_id,
166
      oldTable.device_added,
167
      oldTable.device_removed
168
   from 
169
      ( 
170
         select
171
            device_name,
172
            client_name,
173
            device_added, 
174
            device_removed 
175
         from temp 
176
         ) oldTable
177
      join client on ( client.name = oldTable.client_name )
178
      join device on ( device.name = oldTable.device_name );
179
 
180
/* link a device to a site */
181
truncate table site_device;
182
insert into site_device ( site_id,device_id,created, removed )
183
   select 
184
      site.site_id,
185
      device.device_id,
186
      oldTable.device_added,
187
      oldTable.device_removed
188
   from 
189
      ( 
190
         select
191
            device_name,
192
            site_name,
193
            device_added, 
194
            device_removed 
195
         from temp 
196
         ) oldTable
197
      join site on ( site.name = oldTable.site_name )
198
      join device on ( device.name = oldTable.device_name );
199
 
200
/* link a device to a parent device */
201
truncate table device_device;
202
insert into device_device ( device_id,parent_id,created, removed )
203
   select 
204
      device.device_id,
205
      parent_device.device_id,
206
      oldTable.device_added,
207
      oldTable.device_removed
208
   from 
209
      ( 
210
         select
211
            dev.device_name,
212
            parent.device_name parent,
213
            dev.device_added, 
214
            dev.device_removed 
215
         from temp dev join temp parent on ( dev.part_of = parent.old_device_id )
216
         where dev.part_of is not null 
217
         ) oldTable
218
      join device on ( device.name = oldTable.device_name )
219
      join device parent_device on ( parent_device.name = oldTable.parent );
220
 
221
/* following dumps all the data */
222
/*
223
select
224
   site.name site,
225
   site_own.name site_owner,
226
   client.name device_owned_by,
227
   device_type.name device_type,
228
   device.name device,
229
   parent.parent_name part_of
230
from
231
   device
232
   join device_type using (device_type_id)
233
   join client_device using (device_id)
234
   join client using (client_id)
235
   join site_device using (device_id)
236
   join site using (site_id )
237
   join client_site using (site_id)
238
   join client site_own on (client_site.client_id = site_own.client_id)
239
   left outer join (
240
      select
241
         device.device_id device_id,
242
         device.name device_name,
243
         parent.device_id parent_id,
244
         parent.name parent_name
245
      from 
246
         device 
247
         join device_device using (device_id) 
248
         join device parent on (parent.device_id = device_device.parent_id)
249
   ) parent using ( device_id )
250
order by
251
   client.name,
252
   site.name,
253
   device_type.name,
254
   device.name
255
;
256
*/
34 rodolico 257
 
258
/* now, load the attributes */
259
 
260
/*
261
   this is a big kludge, but since it is only run once, I did not bother optimizing it.
262
   basically, get all the attributes which are used by devices which are systems
263
   and add them to the attribute table
264
*/
265
insert into attribute ( name,attribute_category_id,added,removed)
266
select
267
   camp.attrib.name,
268
   attribute_category.attribute_category_id,
269
   date(camp.attrib.added_date),
270
   date(camp.attrib.removed_date)
271
from
272
   camp.attrib
273
   join camp2.attribute_category
274
where
275
   attribute_category.name = 'device'
276
   and camp.attrib.attrib_id in (
277
      select distinct
278
         attrib_id
279
      from 
280
         camp.device_attrib
281
      where 
282
         camp.device_attrib.device_id in
283
         (
284
            select 
285
               device_id 
286
            from 
287
               camp.device 
288
               join camp.device_type using (device_type_id) 
289
            where 
290
               device_type.show_as_system = 'Y'
291
         )
292
   )
293
   and camp.attrib.name not in (
294
      select 
295
         attribute.name 
296
      from 
297
         attribute 
298
         join attribute_category using (attribute_category_id) 
299
      where 
300
         attribute_category.name = 'device'
301
   );
302
 
303
/*
304
   now, load the values for the devices. NOTE: we should clean up data coming in since sysinfo
305
   brings in values which are only slightly different for memory and cpu speed.
306
*/
307
 
308
insert into attribute_value( attribute_id,table_id,value,added,removed)
309
select 
310
   camp2.attribute.attribute_id,
311
   camp.device_attrib.device_id,
312
   camp.device_attrib.value,
313
   date( camp.device_attrib.added_date ) added,
314
   date( camp.device_attrib.removed_date ) removed
315
from
316
   camp.device_attrib
317
   join camp.attrib on (camp.device_attrib.attrib_id = camp.attrib.attrib_id)
318
   join camp2.attribute on (camp.attrib.name = camp2.attribute.name)
319
   join camp2.temp on ( camp.device_attrib.device_id = camp2.temp.old_device_id )
320
   join camp2.device on (camp2.device.name = camp2.temp.device_name)
321
;
322
 
323
/*
324
   select * from view_attribute_device order by device,attribute,added limit 10;
325
*/