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