Subversion Repositories computer_asset_manager_v2

Rev

Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 63
Line -... Line 1...
-
 
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
 
1
/* This is used to map old ID's to new ones */
6
/* This is used to map old ID's to new ones */
2
create or replace table camp2.mapping (
7
create or replace table camp2.mapping (
3
         tablename varchar(32) not null,
8
         tablename varchar(32) not null,
4
         old_id    int unsigned not null,
9
         old_id    int unsigned not null,
5
         new_id    int unsigned not null,
10
         new_id    int unsigned not null,
Line 22... Line 27...
22
      date(added_date),
27
      date(added_date),
23
      date( removed_date )
28
      date( removed_date )
24
   from
29
   from
25
      camp.login;
30
      camp.login;
26
 
31
 
-
 
32
update camp2._users set isAdmin = 1 where login = 'admin';
-
 
33
 
27
/* Set up mapping between old and new users */
34
/* Set up mapping between old and new users */
28
insert into camp2.mapping ( tablename,new_id,old_id )
35
insert into camp2.mapping ( tablename,new_id,old_id )
29
   select 
36
   select 
30
      '_users',
37
      '_users',
31
      camp2._users._user_id,
38
      camp2._users._user_id,
Line 155... Line 162...
155
            camp2.location_mapping
162
            camp2.location_mapping
156
         where 
163
         where 
157
            camp.site.name like concat( '%',location_mapping.old_value, '%')
164
            camp.site.name like concat( '%',location_mapping.old_value, '%')
158
            and camp.site.name <> 'Colocation NOC'
165
            and camp.site.name <> 'Colocation NOC'
159
         ) site2 on (camp2.location.name = site2.new_value );
166
         ) site2 on (camp2.location.name = site2.new_value );
-
 
167
         
-
 
168
/* clean up */
-
 
169
drop table camp2.location_mapping;
160
 
170
 
161
/* ***************************************
171
/* ***************************************
162
  Devices
172
  Devices
163
*/
173
*/
164
 
174
 
Line 185... Line 195...
185
      camp.device.device_id
195
      camp.device.device_id
186
   from
196
   from
187
      camp2.device
197
      camp2.device
188
      join camp.device on (camp2.device.name = camp.device.name);
198
      join camp.device on (camp2.device.name = camp.device.name);
189
 
199
 
-
 
200
/* ***************************************
-
 
201
  Devices
-
 
202
*/
-
 
203
truncate table camp2.device_type;
-
 
204
insert into camp2.device_type (name,created,removed)
-
 
205
   select
-
 
206
      name,
-
 
207
      date(added_date),
-
 
208
      date(removed_date)
-
 
209
   from
-
 
210
      camp.device_type
-
 
211
   where
-
 
212
      camp.device_type.show_as_system = 'Y';
-
 
213
 
-
 
214
insert into camp2.mapping( tablename, new_id, old_id )
-
 
215
   select
-
 
216
      'device_type',
-
 
217
      camp2.device_type.device_type_id,
-
 
218
      camp.device_type.device_type_id
-
 
219
   from
-
 
220
      camp2.device_type
-
 
221
      join camp.device_type using (name)
-
 
222
   where
-
 
223
      camp.device_type.show_as_system = 'Y';
-
 
224
 
-
 
225
/* *********************************************************
-
 
226
   Linkage Tables
-
 
227
*/
-
 
228
 
-
 
229
/* device_device */
-
 
230
truncate table camp2.device_device;
-
 
231
insert into camp2.device_device (device_id,parent_id,created,removed)
-
 
232
   select
-
 
233
      camp2.mapping.new_id,
-
 
234
      parent.new_id,
-
 
235
      date(now()),
-
 
236
      null
-
 
237
   from
-
 
238
      camp.device
-
 
239
      join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device' )
-
 
240
      join (
-
 
241
         select
-
 
242
            device.device_id,
-
 
243
            mapping.new_id
-
 
244
         from
-
 
245
            camp.device
-
 
246
            join camp2.mapping on (camp.device.device_id = mapping.old_id and camp2.mapping.tablename = 'device')
-
 
247
         ) parent on ( camp.device.part_of = parent.device_id )
-
 
248
   where
-
 
249
      camp.device.device_type_id in (select device_type_id from camp.device_type where show_as_system = 'Y')
-
 
250
      and camp.device.part_of is not null
-
 
251
      and camp.device.removed_date is null;
-
 
252
   
-
 
253
/* use following to verify this is working
-
 
254
 
-
 
255
select 
-
 
256
   device.name device,
-
 
257
   parent.name parent
-
 
258
from 
-
 
259
   device 
-
 
260
   join device_device using (device_id) 
-
 
261
   join device parent on (device_device.parent_id = parent.device_id) 
-
 
262
where 
-
 
263
   device.removed is null
-
 
264
order by parent.name,device.name;
-
 
265
 
-
 
266
*/
-
 
267
 
-
 
268
/* device_device_type */
-
 
269
 
-
 
270
truncate camp2.device_device_type;
-
 
271
insert into camp2.device_device_type (device_id,device_type_id)
-
 
272
   select
-
 
273
      mapping.new_id,
-
 
274
      map_type.new_id
-
 
275
   from
-
 
276
      camp.device
-
 
277
      join camp.device_type on (camp.device.device_type_id = camp.device_type.device_type_id)
-
 
278
      join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
-
 
279
      join camp2.mapping map_type on (camp.device_type.device_type_id = map_type.old_id and map_type.tablename = 'device_type' )
-
 
280
;      
-
 
281
 
-
 
282
/* verify with the following query 
-
 
283
 
-
 
284
select device.name,device_types from device join view_device_device_types using (device_id);
-
 
285
 
-
 
286
*/
-
 
287
 
-
 
288
/* location_device */
-
 
289
truncate table location_device;
-
 
290
insert into location_device ( location_id,device_id,created,removed )
-
 
291
   select
-
 
292
      map_type.new_id,
-
 
293
      mapping.new_id,
-
 
294
      date(camp.site.added_date),
-
 
295
      date(camp.site.removed_date)
-
 
296
   from
-
 
297
      camp.device
-
 
298
      join camp.site using (site_id)
-
 
299
      join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
-
 
300
      join camp2.mapping map_type on (camp.site.site_id = map_type.old_id and map_type.tablename = 'location' )
-
 
301
;      
-
 
302
 
-
 
303
/* Verify with the following query 
-
 
304
 
-
 
305
select 
-
 
306
   device.name,
-
 
307
   location.name
-
 
308
from 
-
 
309
   device 
-
 
310
   join location_device using (device_id) 
-
 
311
   join location using (location_id);
-
 
312
   
-
 
313
*/
-
 
314
 
-
 
315
/* owner_device */
-
 
316
truncate table owner_device;
-
 
317
insert into owner_device ( owner_id,device_id,created,removed )
-
 
318
   select
-
 
319
      map_type.new_id,
-
 
320
      mapping.new_id,
-
 
321
      date(camp.device.added_date),
-
 
322
      date(camp.device.removed_date)
-
 
323
   from
-
 
324
      camp.device
-
 
325
      join camp.site using (site_id)
-
 
326
      join camp.client using (client_id)
-
 
327
      join camp2.mapping on (camp.device.device_id = mapping.old_id and mapping.tablename = 'device')
-
 
328
      join camp2.mapping map_type on (camp.client.client_id = map_type.old_id and map_type.tablename = 'owner' )
-
 
329
;      
-
 
330
 
-
 
331
/* Verify with the following query
-
 
332
 
-
 
333
select owner.name owner, device.name device from owner join owner_device using (owner_id) join device using (device_id);
-
 
334
 
-
 
335
*/
-
 
336
 
-
 
337
 
-
 
338
/* owner_location */
-
 
339
truncate table owner_location;
-
 
340
insert into owner_location ( owner_id,location_id,created,removed )
-
 
341
   select
-
 
342
      map_type.new_id,
-
 
343
      mapping.new_id,
-
 
344
      date(camp.site.added_date),
-
 
345
      date(camp.site.removed_date)
-
 
346
   from
-
 
347
      camp.site
-
 
348
      join camp.client using (client_id)
-
 
349
      join camp2.mapping on (camp.site.site_id = mapping.old_id and mapping.tablename = 'location')
-
 
350
      join camp2.mapping map_type on (camp.client.client_id = map_type.old_id and map_type.tablename = 'owner' )
-
 
351
   where
-
 
352
      camp.site.name in (select name from camp2.location)
-
 
353
;
-
 
354
 
-
 
355
/* Verify with one of the following queries, or, simply open the app
-
 
356
 
-
 
357
select owner.name owner, location.name location from owner join owner_location using (owner_id) join location using (location_id);
-
 
358
select * from view_device_location_owner_type limit 10;
-
 
359
 
-
 
360
*/
-
 
361
 
-
 
362
/* Set a UUID for everything that doesn't have one */
-
 
363
update owner set uuid = uuid() where uuid is null;
-
 
364
update location set uuid = uuid() where uuid is null;
-
 
365
update device set uuid = uuid() where uuid is null;