Subversion Repositories computer_asset_manager_v2

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 rodolico 1
/* This is used to map old ID's to new ones */
2
create or replace table camp2.mapping (
3
         tablename varchar(32) not null,
4
         old_id    int unsigned not null,
5
         new_id    int unsigned not null,
6
         primary key (tablename,old_id,new_id)
7
      );
8
 
9
/* ***************************************
10
    Users
11
*/
12
 
13
/* grab all users in old table and insert here with the "L" password */
14
truncate table camp2._users;
15
insert into camp2._users (login,password,email,isAdmin,enabled,created,removed)
16
   select
17
      if (instr(email,'@'), left(email,instr(email,'@')-1), email),
18
      '$2y$10$GWsjPDZWzCoNuD1lC34PDeyqnjSKI.QAevtRnxpjHpkMIZJJNvK8m',
19
      if (instr(email,'@'), email, concat(email, '@dailydata.net' )),
20
      0,
21
      isnull(removed_date),
22
      date(added_date),
23
      date( removed_date )
24
   from
25
      camp.login;
26
 
27
/* Set up mapping between old and new users */
28
insert into camp2.mapping ( tablename,new_id,old_id )
29
   select 
30
      '_users',
31
      camp2._users._user_id,
32
      camp.login.login_id
33
   from
34
      camp2._users
35
      join camp.login on (camp2._users.login = camp.login.email);
36
 
37
 
38
/* Update all user permissions to default */
39
truncate table  camp2._users_permissions;
40
insert into camp2._users_permissions (_user_id,_permission_id, value )
41
   select 
42
      _user_id,
43
      _permission_id,
44
      1
45
   from 
46
      _permissions 
47
      join _users
48
   where 
49
      _permissions.default_value = 1
50
      and _users._user_id not in (
51
         select 
52
            _users._user_id 
53
         from 
54
            camp2._users_permissions 
55
            join camp2._users using (_user_id)
56
         );
57
 
58
/* *************************************
59
   Owners
60
*/
61
 
62
/* add owners */
63
truncate table camp2.owner;
64
insert into camp2.owner (name,created,removed)
65
   select 
66
      name,
67
      date( added_date ),
68
      date( removed_date)
69
   from 
70
      camp.client;
71
 
72
/* Set up mapping between old and new owners */
73
insert into camp2.mapping ( tablename,new_id,old_id )
74
   select 
75
      'owner',
76
      camp2.owner.owner_id,
77
      camp.client.client_id
78
   from
79
      camp2.owner
80
      join camp.client on (camp2.owner.name = camp.client.name);
81
 
82
/* ************************************************* 
83
   Locations. This is a little different.
84
   We have several things in the old database which were put in there
85
   because location ownership was not different from device ownership
86
   Here, we're building a table to break them apart
87
*/
88
create or replace table camp2.location_mapping (
89
   old_value varchar(64),
90
   new_value varchar(64),
91
   primary key (old_value,new_value)
92
);
93
insert into camp2.location_mapping(old_value,new_value) values ('NOC','Colocation NOC' );
94
insert into camp2.location_mapping(old_value,new_value) values ('Lori Bryant Office','Lori Bryant, CPA - Stemmons Towers');
95
insert into camp2.location_mapping(old_value,new_value) values ('DD Vanduzen','Vanduzen Dallas');
96
insert into camp2.location_mapping(old_value,new_value) values ('Lakewood Title Office','LWT Corp');
97
insert into camp2.location_mapping(old_value,new_value) values ('AppServe (Daily Data)','AppServe Technologies');
98
insert into camp2.location_mapping(old_value,new_value) values ('Staffmasters (Daily Data)','Staffmasters - Stemmons Towers');
99
 
100
 
101
/*
102
   Now, we copy the ones which are NOT found in the above over directly
103
*/
104
truncate table camp2.location;
105
insert into camp2.location (name,created,removed)
106
   select
107
      name,
108
      date(added_date),
109
      date(removed_date)
110
   from
111
      camp.site
112
   where
113
      camp.site.site_id not in
114
         (
115
            select 
116
               camp.site.site_id
117
            from 
118
               camp.site,
119
               location_mapping
120
            where 
121
               camp.site.name like concat( '%',location_mapping.old_value, '%')
122
               and camp.site.name <> 'Colocation NOC'
123
         );
124
 
125
/* Set up mapping between old and new locations, except for the aliases */
126
insert into camp2.mapping ( tablename,new_id,old_id )
127
   select 
128
      'location',
129
      camp2.location.location_id,
130
      camp.site.site_id
131
   from
132
      camp2.location
133
      join camp.site on (camp2.location.name = camp.site.name);
134
 
135
 
136
/* 
137
   Finally, we get the stuff we ignored in location_mapping and work 
138
   with it. We don't add those sites, we just do a mapping for them
139
*/
140
insert into camp2.mapping (tablename,new_id,old_id)
141
   select
142
      'location',
143
      camp2.location.location_id,
144
      site2.site_id
145
   from
146
      location
147
      join (
148
         select 
149
            camp.site.site_id,
150
            camp.site.name,
151
            location_mapping.old_value,
152
            location_mapping.new_value
153
         from 
154
            camp.site,
155
            camp2.location_mapping
156
         where 
157
            camp.site.name like concat( '%',location_mapping.old_value, '%')
158
            and camp.site.name <> 'Colocation NOC'
159
         ) site2 on (camp2.location.name = site2.new_value );
160
 
161
/* ***************************************
162
  Devices
163
*/
164
 
165
/* grab all that are marked as systems, no PCI cards */
166
truncate table camp2.device;
167
insert into camp2.device (uuid,serial,name,created,removed)
168
   select 
169
      if ( length( serial ) = 36, serial, null ) uuid,
170
      if ( length( serial ) < 36, serial, null ) serial,
171
      device.name,
172
      date( device.added_date ),
173
      date( device.removed_date)
174
   from
175
      camp.device
176
      join camp.device_type using ( device_type_id )
177
   where 
178
      device_type.show_as_system = 'Y';
179
 
180
/* Set up mapping between old and new device */
181
insert into camp2.mapping ( tablename,new_id,old_id )
182
   select 
183
      'device',
184
      camp2.device.device_id,
185
      camp.device.device_id
186
   from
187
      camp2.device
188
      join camp.device on (camp2.device.name = camp.device.name);
189