Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
76 rodolico 1
show tables from camp like '%attr%';
2
 
3
/*
4
   get the attribute categories first
5
*/
6
 
7
truncate table attribute_category;
8
insert into attribute_category 
9
   select
10
      null,
11
      name
12
   from camp.attrib_category;
13
 
14
-- update the maps from old to new
15
insert into mapping 
16
   select 
17
      'attribute_category',
18
      camp.attrib_category.attrib_category_id,
19
      attribute_category.attribute_category_id 
20
   from 
21
      camp.attrib_category
22
      join attribute_category using (name);
23
 
24
/*
25
   Now, get the attributes
26
*/
27
truncate table attribute;
28
insert into attribute (
29
   name,
30
   attribute_category_id,
31
   multiples,
32
   display_in_summary,
33
   added,
34
   removed
35
   )
36
   select
37
      name,
38
      new_id,
39
      multiples,
40
      1,
41
      date(added_date),
42
      date(removed_date)
43
   from
44
      camp.attrib
45
      join mapping on (
46
         mapping.tablename='attribute_category'
47
         and mapping.old_id = camp.attrib.attrib_category_id 
48
         );
49
 
50
-- and, update them also
51
insert into mapping 
52
   select 
53
      'attribute',
54
      camp.attrib.attrib_id,
55
      attribute.attribute_id 
56
   from 
57
      camp.attrib
58
      join attribute using (name);
59
 
60
/*
61
   Finally, we get the attributes themselves. In the old system, they were all
62
   device attributes
63
*/
64
 
65
truncate table attribute_value;
66
 
67
insert into attribute_value (
68
   attribute_id,
69
   _base_class_id,
70
   entity_id,
71
   value,
72
   added,
73
   removed
74
   )
75
select 
76
   attrib_map.new_id,
77
   (select _base_class_id from _base_class where class_name = 'Device') class_id,
78
   mapping.new_id,
79
   value,
80
   date(added_date),
81
   date(removed_date)
82
from
83
   camp.attrib_device
84
   join mapping on (
85
      camp.attrib_device.device_id = mapping.old_id
86
      and mapping.tablename = 'device'
87
      )
88
   join mapping as attrib_map on (
89
      camp.attrib_device.attrib_id = attrib_map.old_id
90
      and attrib_map.tablename = 'attribute'
91
   );
92
 
93
-- There is nothing else that depends on these values, so we won't blow up mapping by loading them
94
 
95
-- now, we do want to go ahead and process aliases. Here are the device aliases
96
insert into attribute_value (
97
   attribute_id,
98
   _base_class_id,
99
   entity_id,
100
   value,
101
   added,
102
   removed
103
   )
104
select
105
   (select attribute_id from attribute where name = 'Alias' ) attrib,
106
   (select _base_class_id from _base_class where class_name = 'Device') class_id,
107
   mapping.new_id,
108
   alias,
109
   date(added_date),
110
   date(removed_date)
111
from
112
   camp.device_alias
113
   join mapping on (
114
      mapping.old_id = camp.device_alias.device_id
115
      and mapping.tablename = 'device'
116
      );
117
 
118
-- client aliases
119
insert into attribute_value (
120
   attribute_id,
121
   _base_class_id,
122
   entity_id,
123
   value,
124
   added,
125
   removed
126
   )
127
select
128
   (select attribute_id from attribute where name = 'Alias' ) attrib,
129
   (select _base_class_id from _base_class where class_name = 'Owner') class_id,
130
   mapping.new_id,
131
   alias,
132
   date(added_date),
133
   date(removed_date)
134
from
135
   camp.client_alias
136
   join mapping on (
137
      mapping.old_id = camp.client_alias.client_id
138
      and mapping.tablename = 'owner'
139
      );