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