Subversion Repositories computer_asset_manager_v2

Rev

Rev 76 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

show tables from camp like '%attr%';

/*
   get the attribute categories first
*/

truncate table attribute_category;
insert into attribute_category 
   select
      null,
      name
   from camp.attrib_category;

-- update the maps from old to new
insert into mapping 
   select 
      'attribute_category',
      camp.attrib_category.attrib_category_id,
      attribute_category.attribute_category_id 
   from 
      camp.attrib_category
      join attribute_category using (name);

/*
   Now, get the attributes
*/
truncate table attribute;
insert into attribute (
   name,
   attribute_category_id,
   multiples,
   display_in_summary,
   added,
   removed
   )
   select
      name,
      new_id,
      multiples,
      1,
      date(added_date),
      date(removed_date)
   from
      camp.attrib
      join mapping on (
         mapping.tablename='attribute_category'
         and mapping.old_id = camp.attrib.attrib_category_id 
         );

-- and, update them also
insert into mapping 
   select 
      'attribute',
      camp.attrib.attrib_id,
      attribute.attribute_id 
   from 
      camp.attrib
      join attribute using (name);

/*
   Finally, we get the attributes themselves. In the old system, they were all
   device attributes
*/

truncate table attribute_value;

insert into attribute_value (
   attribute_id,
   _base_class_id,
   entity_id,
   value,
   added,
   removed
   )
select 
   attrib_map.new_id,
   (select _base_class_id from _base_class where class_name = 'Device') class_id,
   mapping.new_id,
   value,
   date(added_date),
   date(removed_date)
from
   camp.attrib_device
   join mapping on (
      camp.attrib_device.device_id = mapping.old_id
      and mapping.tablename = 'device'
      )
   join mapping as attrib_map on (
      camp.attrib_device.attrib_id = attrib_map.old_id
      and attrib_map.tablename = 'attribute'
   );

-- There is nothing else that depends on these values, so we won't blow up mapping by loading them

-- now, we do want to go ahead and process aliases. Here are the device aliases
insert into attribute_value (
   attribute_id,
   _base_class_id,
   entity_id,
   value,
   added,
   removed
   )
select
   (select attribute_id from attribute where name = 'Alias' ) attrib,
   (select _base_class_id from _base_class where class_name = 'Device') class_id,
   mapping.new_id,
   alias,
   date(added_date),
   date(removed_date)
from
   camp.device_alias
   join mapping on (
      mapping.old_id = camp.device_alias.device_id
      and mapping.tablename = 'device'
      );

-- client aliases
insert into attribute_value (
   attribute_id,
   _base_class_id,
   entity_id,
   value,
   added,
   removed
   )
select
   (select attribute_id from attribute where name = 'Alias' ) attrib,
   (select _base_class_id from _base_class where class_name = 'Owner') class_id,
   mapping.new_id,
   alias,
   date(added_date),
   date(removed_date)
from
   camp.client_alias
   join mapping on (
      mapping.old_id = camp.client_alias.client_id
      and mapping.tablename = 'owner'
      );

Generated by GNU Enscript 1.6.5.90.