63 |
rodolico |
1 |
/*
|
|
|
2 |
This is a helper script to import CAMP v1 to CAMP v2. There are some
|
|
|
3 |
customizations for our purposes, but it is mainly generic.
|
|
|
4 |
*/
|
|
|
5 |
|
61 |
rodolico |
6 |
/* This is used to map old ID's to new ones */
|
|
|
7 |
create or replace table camp2.mapping (
|
|
|
8 |
tablename varchar(32) not null,
|
|
|
9 |
old_id int unsigned not null,
|
|
|
10 |
new_id int unsigned not null,
|
|
|
11 |
primary key (tablename,old_id,new_id)
|
|
|
12 |
);
|
|
|
13 |
|
|
|
14 |
/* ***************************************
|
|
|
15 |
Users
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
/* grab all users in old table and insert here with the "L" password */
|
|
|
19 |
truncate table camp2._users;
|
|
|
20 |
insert into camp2._users (login,password,email,isAdmin,enabled,created,removed)
|
|
|
21 |
select
|
|
|
22 |
if (instr(email,'@'), left(email,instr(email,'@')-1), email),
|
|
|
23 |
'$2y$10$GWsjPDZWzCoNuD1lC34PDeyqnjSKI.QAevtRnxpjHpkMIZJJNvK8m',
|
|
|
24 |
if (instr(email,'@'), email, concat(email, '@dailydata.net' )),
|
|
|
25 |
0,
|
|
|
26 |
isnull(removed_date),
|
|
|
27 |
date(added_date),
|
|
|
28 |
date( removed_date )
|
|
|
29 |
from
|
|
|
30 |
camp.login;
|
|
|
31 |
|
63 |
rodolico |
32 |
update camp2._users set isAdmin = 1 where login = 'admin';
|
|
|
33 |
|
61 |
rodolico |
34 |
/* Set up mapping between old and new users */
|
|
|
35 |
insert into camp2.mapping ( tablename,new_id,old_id )
|
|
|
36 |
select
|
|
|
37 |
'_users',
|
|
|
38 |
camp2._users._user_id,
|
|
|
39 |
camp.login.login_id
|
|
|
40 |
from
|
|
|
41 |
camp2._users
|
|
|
42 |
join camp.login on (camp2._users.login = camp.login.email);
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
/* Update all user permissions to default */
|
|
|
46 |
truncate table camp2._users_permissions;
|
|
|
47 |
insert into camp2._users_permissions (_user_id,_permission_id, value )
|
|
|
48 |
select
|
|
|
49 |
_user_id,
|
|
|
50 |
_permission_id,
|
|
|
51 |
1
|
|
|
52 |
from
|
|
|
53 |
_permissions
|
|
|
54 |
join _users
|
|
|
55 |
where
|
|
|
56 |
_permissions.default_value = 1
|
|
|
57 |
and _users._user_id not in (
|
|
|
58 |
select
|
|
|
59 |
_users._user_id
|
|
|
60 |
from
|
|
|
61 |
camp2._users_permissions
|
|
|
62 |
join camp2._users using (_user_id)
|
|
|
63 |
);
|
66 |
rodolico |
64 |
|
|
|
65 |
update _users set restrictions = '[owner]
|
|
|
66 |
Vanduzen' where login = 'jbellah';
|
61 |
rodolico |
67 |
|
66 |
rodolico |
68 |
update _users set restrictions = '[owner]
|
|
|
69 |
Walder IP Law' where login = 'swalder';
|
|
|
70 |
|
|
|
71 |
|
61 |
rodolico |
72 |
/* *************************************
|
|
|
73 |
Owners
|
|
|
74 |
*/
|
|
|
75 |
|
|
|
76 |
/* add owners */
|
|
|
77 |
truncate table camp2.owner;
|
|
|
78 |
insert into camp2.owner (name,created,removed)
|
|
|
79 |
select
|
|
|
80 |
name,
|
|
|
81 |
date( added_date ),
|
|
|
82 |
date( removed_date)
|
|
|
83 |
from
|
|
|
84 |
camp.client;
|
|
|
85 |
|
|
|
86 |
/* Set up mapping between old and new owners */
|
|
|
87 |
insert into camp2.mapping ( tablename,new_id,old_id )
|
|
|
88 |
select
|
|
|
89 |
'owner',
|
|
|
90 |
camp2.owner.owner_id,
|
|
|
91 |
camp.client.client_id
|
|
|
92 |
from
|
|
|
93 |
camp2.owner
|
|
|
94 |
join camp.client on (camp2.owner.name = camp.client.name);
|
|
|
95 |
|
|
|
96 |
/* *************************************************
|
|
|
97 |
Locations. This is a little different.
|
|
|
98 |
We have several things in the old database which were put in there
|
|
|
99 |
because location ownership was not different from device ownership
|
|
|
100 |
Here, we're building a table to break them apart
|
|
|
101 |
*/
|
|
|
102 |
create or replace table camp2.location_mapping (
|
|
|
103 |
old_value varchar(64),
|
|
|
104 |
new_value varchar(64),
|
|
|
105 |
primary key (old_value,new_value)
|
|
|
106 |
);
|
|
|
107 |
insert into camp2.location_mapping(old_value,new_value) values ('NOC','Colocation NOC' );
|
|
|
108 |
insert into camp2.location_mapping(old_value,new_value) values ('Lori Bryant Office','Lori Bryant, CPA - Stemmons Towers');
|
|
|
109 |
insert into camp2.location_mapping(old_value,new_value) values ('DD Vanduzen','Vanduzen Dallas');
|
|
|
110 |
insert into camp2.location_mapping(old_value,new_value) values ('Lakewood Title Office','LWT Corp');
|
|
|
111 |
insert into camp2.location_mapping(old_value,new_value) values ('AppServe (Daily Data)','AppServe Technologies');
|
|
|
112 |
insert into camp2.location_mapping(old_value,new_value) values ('Staffmasters (Daily Data)','Staffmasters - Stemmons Towers');
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
/*
|
|
|
116 |
Now, we copy the ones which are NOT found in the above over directly
|
|
|
117 |
*/
|
|
|
118 |
truncate table camp2.location;
|
|
|
119 |
insert into camp2.location (name,created,removed)
|
|
|
120 |
select
|
|
|
121 |
name,
|
|
|
122 |
date(added_date),
|
|
|
123 |
date(removed_date)
|
|
|
124 |
from
|
|
|
125 |
camp.site
|
|
|
126 |
where
|
|
|
127 |
camp.site.site_id not in
|
|
|
128 |
(
|
|
|
129 |
select
|
|
|
130 |
camp.site.site_id
|
|
|
131 |
from
|
|
|
132 |
camp.site,
|
|
|
133 |
location_mapping
|
|
|
134 |
where
|
|
|
135 |
camp.site.name like concat( '%',location_mapping.old_value, '%')
|
|
|
136 |
and camp.site.name <> 'Colocation NOC'
|
|
|
137 |
);
|
|
|
138 |
|
|
|
139 |
/* Set up mapping between old and new locations, except for the aliases */
|
|
|
140 |
insert into camp2.mapping ( tablename,new_id,old_id )
|
|
|
141 |
select
|
|
|
142 |
'location',
|
|
|
143 |
camp2.location.location_id,
|
|
|
144 |
camp.site.site_id
|
|
|
145 |
from
|
|
|
146 |
camp2.location
|
|
|
147 |
join camp.site on (camp2.location.name = camp.site.name);
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
/*
|
|
|
151 |
Finally, we get the stuff we ignored in location_mapping and work
|
|
|
152 |
with it. We don't add those sites, we just do a mapping for them
|
|
|
153 |
*/
|
|
|
154 |
insert into camp2.mapping (tablename,new_id,old_id)
|
|
|
155 |
select
|
|
|
156 |
'location',
|
|
|
157 |
camp2.location.location_id,
|
|
|
158 |
site2.site_id
|
|
|
159 |
from
|
|
|
160 |
location
|
|
|
161 |
join (
|
|
|
162 |
select
|
|
|
163 |
camp.site.site_id,
|
|
|
164 |
camp.site.name,
|
|
|
165 |
location_mapping.old_value,
|
|
|
166 |
location_mapping.new_value
|
|
|
167 |
from
|
|
|
168 |
camp.site,
|
|
|
169 |
camp2.location_mapping
|
|
|
170 |
where
|
|
|
171 |
camp.site.name like concat( '%',location_mapping.old_value, '%')
|
|
|
172 |
and camp.site.name <> 'Colocation NOC'
|
|
|
173 |
) site2 on (camp2.location.name = site2.new_value );
|
63 |
rodolico |
174 |
|
|
|
175 |
/* clean up */
|
|
|
176 |
drop table camp2.location_mapping;
|
61 |
rodolico |
177 |
|
|
|
178 |
/* ***************************************
|
|
|
179 |
Devices
|
|
|
180 |
*/
|
|
|
181 |
|
|
|
182 |
/* grab all that are marked as systems, no PCI cards */
|
|
|
183 |
truncate table camp2.device;
|
|
|
184 |
insert into camp2.device (uuid,serial,name,created,removed)
|
|
|
185 |
select
|
|
|
186 |
if ( length( serial ) = 36, serial, null ) uuid,
|
|
|
187 |
if ( length( serial ) < 36, serial, null ) serial,
|
|
|
188 |
device.name,
|
|
|
189 |
date( device.added_date ),
|
|
|
190 |
date( device.removed_date)
|
|
|
191 |
from
|
|
|
192 |
camp.device
|
|
|
193 |
join camp.device_type using ( device_type_id )
|
|
|
194 |
where
|
|
|
195 |
device_type.show_as_system = 'Y';
|
|
|
196 |
|
|
|
197 |
/* Set up mapping between old and new device */
|
|
|
198 |
insert into camp2.mapping ( tablename,new_id,old_id )
|
|
|
199 |
select
|
|
|
200 |
'device',
|
|
|
201 |
camp2.device.device_id,
|
|
|
202 |
camp.device.device_id
|
|
|
203 |
from
|
|
|
204 |
camp2.device
|
|
|
205 |
join camp.device on (camp2.device.name = camp.device.name);
|
|
|
206 |
|
63 |
rodolico |
207 |
/* ***************************************
|
|
|
208 |
Devices
|
|
|
209 |
*/
|
|
|
210 |
truncate table camp2.device_type;
|
66 |
rodolico |
211 |
insert into camp2.device_type (name,created)
|
63 |
rodolico |
212 |
select
|
|
|
213 |
name,
|
66 |
rodolico |
214 |
date(added_date)
|
63 |
rodolico |
215 |
from
|
|
|
216 |
camp.device_type
|
|
|
217 |
where
|
|
|
218 |
camp.device_type.show_as_system = 'Y';
|
|
|
219 |
|
|
|
220 |
insert into camp2.mapping( tablename, new_id, old_id )
|
|
|
221 |
select
|
|
|
222 |
'device_type',
|
|
|
223 |
camp2.device_type.device_type_id,
|
|
|
224 |
camp.device_type.device_type_id
|
|
|
225 |
from
|
|
|
226 |
camp2.device_type
|
|
|
227 |
join camp.device_type using (name)
|
|
|
228 |
where
|
|
|
229 |
camp.device_type.show_as_system = 'Y';
|
|
|
230 |
|
|
|
231 |
/* *********************************************************
|
|
|
232 |
Linkage Tables
|
|
|
233 |
*/
|
|
|
234 |
|
|
|
235 |
/* device_device */
|
|
|
236 |
truncate table camp2.device_device;
|
66 |
rodolico |
237 |
insert into camp2.device_device (device_id,parent_id,created)
|
63 |
rodolico |
238 |
select
|
|
|
239 |
camp2.mapping.new_id,
|
|
|
240 |
parent.new_id,
|
66 |
rodolico |
241 |
date(now())
|
63 |
rodolico |
242 |
from
|
|
|
243 |
camp.device
|
|
|
244 |
join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device' )
|
|
|
245 |
join (
|
|
|
246 |
select
|
|
|
247 |
device.device_id,
|
|
|
248 |
mapping.new_id
|
|
|
249 |
from
|
|
|
250 |
camp.device
|
|
|
251 |
join camp2.mapping on (camp.device.device_id = mapping.old_id and camp2.mapping.tablename = 'device')
|
|
|
252 |
) parent on ( camp.device.part_of = parent.device_id )
|
|
|
253 |
where
|
|
|
254 |
camp.device.device_type_id in (select device_type_id from camp.device_type where show_as_system = 'Y')
|
|
|
255 |
and camp.device.part_of is not null
|
|
|
256 |
and camp.device.removed_date is null;
|
|
|
257 |
|
|
|
258 |
/* use following to verify this is working
|
|
|
259 |
|
|
|
260 |
select
|
|
|
261 |
device.name device,
|
|
|
262 |
parent.name parent
|
|
|
263 |
from
|
|
|
264 |
device
|
|
|
265 |
join device_device using (device_id)
|
|
|
266 |
join device parent on (device_device.parent_id = parent.device_id)
|
|
|
267 |
where
|
|
|
268 |
device.removed is null
|
|
|
269 |
order by parent.name,device.name;
|
|
|
270 |
|
|
|
271 |
*/
|
|
|
272 |
|
|
|
273 |
/* device_device_type */
|
|
|
274 |
|
|
|
275 |
truncate camp2.device_device_type;
|
|
|
276 |
insert into camp2.device_device_type (device_id,device_type_id)
|
|
|
277 |
select
|
|
|
278 |
mapping.new_id,
|
|
|
279 |
map_type.new_id
|
|
|
280 |
from
|
|
|
281 |
camp.device
|
|
|
282 |
join camp.device_type on (camp.device.device_type_id = camp.device_type.device_type_id)
|
|
|
283 |
join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
|
|
|
284 |
join camp2.mapping map_type on (camp.device_type.device_type_id = map_type.old_id and map_type.tablename = 'device_type' )
|
|
|
285 |
;
|
|
|
286 |
|
|
|
287 |
/* verify with the following query
|
|
|
288 |
|
66 |
rodolico |
289 |
select device.name,device_types from device join view_device_types using (device_id);
|
63 |
rodolico |
290 |
|
|
|
291 |
*/
|
|
|
292 |
|
|
|
293 |
/* location_device */
|
|
|
294 |
truncate table location_device;
|
66 |
rodolico |
295 |
insert into location_device ( location_id,device_id,created )
|
63 |
rodolico |
296 |
select
|
|
|
297 |
map_type.new_id,
|
|
|
298 |
mapping.new_id,
|
66 |
rodolico |
299 |
date(camp.site.added_date)
|
63 |
rodolico |
300 |
from
|
|
|
301 |
camp.device
|
|
|
302 |
join camp.site using (site_id)
|
|
|
303 |
join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
|
|
|
304 |
join camp2.mapping map_type on (camp.site.site_id = map_type.old_id and map_type.tablename = 'location' )
|
|
|
305 |
;
|
|
|
306 |
|
|
|
307 |
/* Verify with the following query
|
|
|
308 |
|
|
|
309 |
select
|
|
|
310 |
device.name,
|
|
|
311 |
location.name
|
|
|
312 |
from
|
|
|
313 |
device
|
|
|
314 |
join location_device using (device_id)
|
|
|
315 |
join location using (location_id);
|
|
|
316 |
|
|
|
317 |
*/
|
|
|
318 |
|
|
|
319 |
/* owner_device */
|
|
|
320 |
truncate table owner_device;
|
66 |
rodolico |
321 |
insert into owner_device ( owner_id,device_id,created )
|
63 |
rodolico |
322 |
select
|
|
|
323 |
map_type.new_id,
|
|
|
324 |
mapping.new_id,
|
66 |
rodolico |
325 |
date(camp.device.added_date)
|
63 |
rodolico |
326 |
from
|
|
|
327 |
camp.device
|
|
|
328 |
join camp.site using (site_id)
|
|
|
329 |
join camp.client using (client_id)
|
|
|
330 |
join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
|
|
|
331 |
join camp2.mapping map_type on (camp.client.client_id = map_type.old_id and map_type.tablename = 'owner' )
|
|
|
332 |
;
|
|
|
333 |
|
|
|
334 |
/* Verify with the following query
|
|
|
335 |
|
|
|
336 |
select owner.name owner, device.name device from owner join owner_device using (owner_id) join device using (device_id);
|
|
|
337 |
|
|
|
338 |
*/
|
|
|
339 |
|
|
|
340 |
|
|
|
341 |
/* owner_location */
|
|
|
342 |
truncate table owner_location;
|
66 |
rodolico |
343 |
insert into owner_location ( owner_id,location_id,created )
|
63 |
rodolico |
344 |
select
|
|
|
345 |
map_type.new_id,
|
|
|
346 |
mapping.new_id,
|
66 |
rodolico |
347 |
date(camp.site.added_date)
|
63 |
rodolico |
348 |
from
|
|
|
349 |
camp.site
|
|
|
350 |
join camp.client using (client_id)
|
|
|
351 |
join camp2.mapping on (camp.site.site_id = mapping.old_id and mapping.tablename = 'location')
|
|
|
352 |
join camp2.mapping map_type on (camp.client.client_id = map_type.old_id and map_type.tablename = 'owner' )
|
|
|
353 |
where
|
|
|
354 |
camp.site.name in (select name from camp2.location)
|
|
|
355 |
;
|
|
|
356 |
|
|
|
357 |
/* Verify with one of the following queries, or, simply open the app
|
|
|
358 |
|
|
|
359 |
select owner.name owner, location.name location from owner join owner_location using (owner_id) join location using (location_id);
|
|
|
360 |
select * from view_device_location_owner_type limit 10;
|
|
|
361 |
|
|
|
362 |
*/
|
|
|
363 |
|