Project

General

Profile

DB Migration Process » History » Version 12

Amber Herold, 02/03/2010 02:56 PM

1 1 Amber Herold
h1. DB Migration Process
2
3 3 Amber Herold
The tables that will be affected are in the dbemdata database and the project database. 
4
Migrate the user data from project to dbemdata because dbemdata is already in Sinedon format. 
5 4 Amber Herold
6 5 Amber Herold
7 1 Amber Herold
+dbemdata+
8
9
* GroupData
10 10 Amber Herold
* UserData (81 rows)
11 1 Amber Herold
12
+project+
13
14 10 Amber Herold
* users (233 rows)
15
* login (187 rows)
16
* pis (145 rows)
17 1 Amber Herold
* userdetails
18
* projectowner
19 5 Amber Herold
20 6 Amber Herold
Future:
21 5 Amber Herold
Eventually, we would like to have 3 databases, appion, leginon and project. The user related tables in dbemdata would be moved to project.
22
All the tables in project still need to be converted to Sinedon format.
23 2 Amber Herold
24
h2. 1 Add new columns to UserData
25
26
Add:
27
28
* username
29
* fullname
30
* firstname
31
* lastname
32
* password
33
* email
34
35
Leave the existing columns as is. Use of "name" and "full name" (with a space) will be phased out.
36 1 Amber Herold
37 3 Amber Herold
h2. 2 Copy data to the UserData table
38
39
From users, copy username, firstname, lastname to UserData.
40 12 Amber Herold
41
h3. Update existing dbemdata.UserData entries with information from project.users when the names match.
42
43
@UPDATE UserData, project.users, project.login
44
    SET UserData.username=project.users.username,
45
        UserData.firstname=project.users.firstname,
46
        UserData.lastname=project.users.lastname,
47
        UserData.email=project.users.email 
48
    WHERE UserData.`full name` like concat(project.users.firstname, ' ',project.users.lastname) 
49
          and project.login.userId = project.users.userId 
50
          and project.users.userId not in(63,211)
51
          and UserData.DEF_id != 54@
52
53
h3. Some names did not match exactly. Update these seperatly.
54
55
56
<pre>
57
//Palida?
58
UPDATE UserData, projectdata.users
59
    SET UserData.username=projectdata.users.username,
60
        UserData.firstname=projectdata.users.firstname,
61
        UserData.lastname=projectdata.users.lastname,
62
        UserData.email=projectdata.users.email 
63
    WHERE projectdata.users.userId = 42
64
          AND UserData.DEF_id = 25
65
66
//Gabe?
67
UPDATE UserData, projectdata.users
68
    SET UserData.username=projectdata.users.username,
69
        UserData.firstname=projectdata.users.firstname,
70
        UserData.lastname=projectdata.users.lastname,
71
        UserData.email=projectdata.users.email 
72
    WHERE projectdata.users.userId = 65
73
          AND UserData.DEF_id = 29
74
75
//Edward Bridgnole
76
UPDATE UserData, projectdata.users
77
    SET UserData.username=projectdata.users.username,
78
        UserData.firstname=projectdata.users.firstname,
79
        UserData.lastname=projectdata.users.lastname,
80
        UserData.email=projectdata.users.email 
81
    WHERE projectdata.users.userId = 78
82
          AND UserData.DEF_id = 41
83
84
//Pickwei
85
UPDATE UserData, projectdata.users
86
    SET UserData.username=projectdata.users.username,
87
        UserData.firstname=projectdata.users.firstname,
88
        UserData.lastname=projectdata.users.lastname,
89
        UserData.email=projectdata.users.email 
90
    WHERE projectdata.users.userId = 122
91
          AND UserData.DEF_id = 57
92
93
//Mark Daniels
94
UPDATE UserData, projectdata.users
95
    SET UserData.username=projectdata.users.username,
96
        UserData.firstname=projectdata.users.firstname,
97
        UserData.lastname=projectdata.users.lastname,
98
        UserData.email=projectdata.users.email 
99
    WHERE projectdata.users.userId = 199
100
          AND UserData.DEF_id = 65
101
102
//Chris Arthur
103
UPDATE UserData, projectdata.users
104
    SET UserData.username=projectdata.users.username,
105
        UserData.firstname=projectdata.users.firstname,
106
        UserData.lastname=projectdata.users.lastname,
107
        UserData.email=projectdata.users.email 
108
    WHERE projectdata.users.userId = 35
109
          AND UserData.DEF_id = 67
110
111
//Fei Sun
112
UPDATE UserData, projectdata.users
113
    SET UserData.username=projectdata.users.username,
114
        UserData.firstname=projectdata.users.firstname,
115
        UserData.lastname=projectdata.users.lastname,
116
        UserData.email=projectdata.users.email 
117
    WHERE projectdata.users.userId = 233
118
          AND UserData.DEF_id = 76
119
120
//Chi-yu Fu
121
UPDATE UserData, projectdata.users
122
    SET UserData.username=projectdata.users.username,
123
        UserData.firstname=projectdata.users.firstname,
124
        UserData.lastname=projectdata.users.lastname,
125
        UserData.email=projectdata.users.email 
126
    WHERE projectdata.users.userId = 245
127
          AND UserData.DEF_id = 78
128
129
//Otomo Takanori	uId=79	puId=252
130
UPDATE UserData, projectdata.users
131
    SET UserData.username=projectdata.users.username,
132
        UserData.firstname=projectdata.users.firstname,
133
        UserData.lastname=projectdata.users.lastname,
134
        UserData.email=projectdata.users.email 
135
    WHERE projectdata.users.userId = 252
136
          AND UserData.DEF_id = 79
137
</pre>
138
139
h3. Insert the rest of the project.users entries into the dbemdata.UserData table.
140
141
This inserts users that have a corresponding project.login entry and have not already been merged into existing dbemdata.UserData entries. 
142
NRAMM usernames with no login entry are not transferred.
143
144
<pre>
145
INSERT INTO dbemdata.UserData (username, firstname, lastname, email)
146
SELECT projectdata.users.username,projectdata.users.firstname, projectdata.users.lastname,projectdata.users.email
147
FROM projectdata.users
148
WHERE projectdata.users.userId IN (SELECT projectdata.login.userId FROM projectdata.login)
149
AND (projectdata.users.userId NOT IN 
150
(
151
    SELECT projectdata.users.userId userId
152
    FROM dbemdata.UserData, projectdata.users, projectdata.login
153
    WHERE dbemdata.UserData.`full name` LIKE concat( projectdata.users.firstname, ' ', projectdata.users.lastname )
154
    AND projectdata.login.userId = projectdata.users.userId
155
)
156
AND projectdata.users.userId NOT IN ( 42, 65, 78, 122, 199, 35, 233, 245, 252, 63, 211 ))
157
</pre>
158
159
160
h3. From project.login, copy user password to dbemdata.UserData.
161
162
163
<pre>
164
UPDATE dbemdata.UserData, projectdata.login
165
SET dbemdata.UserData.password=projectdata.login.password
166
WHERE dbemdata.UserData.username = projectdata.login.username
167
</pre>
168 3 Amber Herold
169
h2. 3 Create projectowner table
170
171
Move the data from pis table to a new projectowner table in the project database. This table will refer to users in the UserData table. 
172
We will phase out use of the pis table. 
173
174 9 Amber Herold
h2. 4 Modify userdetails table
175 3 Amber Herold
176 1 Amber Herold
Remove the email column from the userdetails table.
177 11 Amber Herold
From users, copy all needed fields.
178 2 Amber Herold