Subversion Repositories computer_asset_manager_v2

Rev

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
 
47 rodolico 9
Monster table of owner, location, device and device_type
33 rodolico 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
 
40 rodolico 45
 
33 rodolico 46
/*
40 rodolico 47
  uuid and serial number are stored A) in the table and B) in the attrib_device table.
48
  We are doing a kludge. If the value is 36 characters long, we assume it is a UUID. If 
49
  it is not, we assume it is a serial number
50
*/
51
 
48 rodolico 52
alter table temp add device_uuid varchar(36);
53
 
40 rodolico 54
update temp a join camp.attrib_device b on (a.old_device_id = b.device_id and b.attrib_id = 23 )
55
  set
56
     a.device_uuid = b.value
57
   where a.device_uuid is null;
58
 
59
update temp a join camp.attrib_device b on (a.old_device_id = b.device_id and b.attrib_id = 3 )
60
  set
61
     a.device_serial = b.value
62
   where a.device_serial is null
63
      and length( b.value ) <> 36;
64
 
65
update temp a join camp.attrib_device b on (a.old_device_id = b.device_id and b.attrib_id = 3 )
66
  set
67
     a.device_uuid = b.value
68
   where a.device_uuid is null
69
      and length( b.value ) = 36;
48 rodolico 70
 
71
update temp set device_uuid = device_serial where length( device_serial ) = 36 and device_uuid is null;
72
update temp set device_serial = null where lower( device_serial ) = lower( device_uuid);
40 rodolico 73
 
74
update temp set device_uuid = trim(device_uuid);
75
update temp set device_serial = trim(device_serial);
76
 
77
update temp set device_uuid = null where length( device_uuid ) = 0;
78
update temp set device_serial = null where length( device_serial ) = 0;
79
 
80
 
81
/*
47 rodolico 82
   in the old system, there was no deliniation between location and client, so we created new 'locations' with 'NOC' at the end
33 rodolico 83
   so we could have ownership and locations. So, fivestar equipment located at the NOC would have been put at the fictitious
47 rodolico 84
   location 'fivestar NOC'. Modified original data so every NOC location has NOC in the name.
85
   Following query puts them all in 'Colocation NOC' (Daily Data's location) without losing ownership information
33 rodolico 86
*/
87
 
88
update temp a
89
   join temp b
90
set
91
   a.old_site_id = b.old_site_id,
92
   a.site_name = b.site_name,
93
   a.site_added = b.site_added,
94
   a.site_owner = b.site_owner
95
where
96
   b.site_name = 'Colocation NOC'
97
   and a.site_name like '%NOC%' and a.site_name <> 'Colocation NOC';
98
 
99
 
100
/* we have some stuff at Lori Bryant's office also */
101
update temp a
102
   join temp b
103
set
104
   a.old_site_id = b.old_site_id,
105
   a.site_name = b.site_name,
106
   a.site_added = b.site_added,
107
   a.site_owner = b.site_owner
108
where
109
   b.site_name = 'Stemmons Towers'
110
   and a.site_name like 'Lori Bryant''s Office';
111
 
112
/* and Lakewood Title */
113
update temp a
114
   join temp b
115
set
116
   a.old_site_id = b.old_site_id,
117
   a.site_name = b.site_name,
118
   a.site_added = b.site_added,
119
   a.site_owner = b.site_owner
120
where
121
   b.site_name = 'Matilda and Prospect'
122
   and a.site_name like 'Lakewood Title Office';
123
 
47 rodolico 124
/* populate owner table */
125
truncate table owner;
126
insert into owner( name,created, removed)
33 rodolico 127
   select distinct
128
      client_name,
129
      client_added,
130
      client_removed
131
   from temp;
132
 
47 rodolico 133
/* populate location */
134
truncate table location;
135
insert into location( name,created,removed) 
33 rodolico 136
   select distinct 
137
      site_name,
138
      site_added,
139
      site_removed
140
   from 
141
      temp;
142
 
143
/* get device_type directly from camp, but ignore anything not set as show_as_system */
144
truncate table device_type;
47 rodolico 145
insert into device_type (name,is_system, created, removed)
33 rodolico 146
select 
147
   name,
148
   true,
149
   date( added_date ),
150
   date( removed_date )
151
from
152
   camp.device_type
153
where
154
   show_as_system = 'Y';
155
 
156
/* Now, we're ready to get some devices */
157
truncate table device;
40 rodolico 158
insert into device( uuid,serial,name,created,removed)
48 rodolico 159
   select distinct
40 rodolico 160
      device_uuid,
48 rodolico 161
      left(device_serial,32),
33 rodolico 162
      device_name,
163
      device_added,
164
      device_removed
165
   from
166
      temp
40 rodolico 167
      join device_type on ( temp.device_type = device_type.name );
33 rodolico 168
 
40 rodolico 169
 
170
/* get all the device types set up */
171
 
172
truncate table device_device_type;
173
insert into device_device_type (device_id,device_type_id )
174
   select 
175
      device.device_id,
176
      device_type_id
177
   from 
178
      temp 
179
      join device on (temp.device_name = device.name) 
180
      join device_type on (temp.device_type = device_type.name);
181
 
182
 
47 rodolico 183
/* link a owner owner to a location */
184
truncate table owner_location;
185
insert into owner_location ( owner_id,location_id,created, removed )
33 rodolico 186
   select 
47 rodolico 187
      owner.owner_id,
188
      location.location_id,
33 rodolico 189
      oldTable.site_added,
190
      oldTable.site_removed
191
   from 
192
      ( 
193
         select distinct 
194
            site_name,
195
            site_owner,
196
            site_added, 
197
            site_removed 
198
         from temp 
199
         ) oldTable
47 rodolico 200
      join owner on ( owner.name = oldTable.site_owner )
201
      join location on ( location.name = oldTable.site_name );
33 rodolico 202
 
203
 
204
/* verify linkage with 
47 rodolico 205
   select owner.name,location.name from owner join owner_location using ( owner_id ) join location using (location_id );
33 rodolico 206
*/
207
 
208
/* link a client owner to a device */
47 rodolico 209
truncate table owner_device;
210
insert into owner_device ( owner_id,device_id,created, removed )
33 rodolico 211
   select 
47 rodolico 212
      owner.owner_id,
33 rodolico 213
      device.device_id,
214
      oldTable.device_added,
215
      oldTable.device_removed
216
   from 
217
      ( 
218
         select
219
            device_name,
220
            client_name,
221
            device_added, 
222
            device_removed 
223
         from temp 
224
         ) oldTable
47 rodolico 225
      join owner on ( owner.name = oldTable.client_name )
33 rodolico 226
      join device on ( device.name = oldTable.device_name );
227
 
47 rodolico 228
/* link a device to a location */
229
truncate table location_device;
230
insert into location_device ( location_id,device_id,created, removed )
33 rodolico 231
   select 
47 rodolico 232
      location.location_id,
33 rodolico 233
      device.device_id,
234
      oldTable.device_added,
235
      oldTable.device_removed
236
   from 
237
      ( 
238
         select
239
            device_name,
240
            site_name,
241
            device_added, 
242
            device_removed 
243
         from temp 
244
         ) oldTable
47 rodolico 245
      join location on ( location.name = oldTable.site_name )
33 rodolico 246
      join device on ( device.name = oldTable.device_name );
247
 
248
/* link a device to a parent device */
249
truncate table device_device;
250
insert into device_device ( device_id,parent_id,created, removed )
251
   select 
252
      device.device_id,
253
      parent_device.device_id,
254
      oldTable.device_added,
255
      oldTable.device_removed
256
   from 
257
      ( 
258
         select
259
            dev.device_name,
260
            parent.device_name parent,
261
            dev.device_added, 
262
            dev.device_removed 
263
         from temp dev join temp parent on ( dev.part_of = parent.old_device_id )
264
         where dev.part_of is not null 
265
         ) oldTable
266
      join device on ( device.name = oldTable.device_name )
267
      join device parent_device on ( parent_device.name = oldTable.parent );
40 rodolico 268
 
33 rodolico 269
 
48 rodolico 270
-- get rid of the temp table
271
drop table if exists temp;