Bye bye auth_user_quick...
[platal.git] / upgrade / account / 99_insertion.sql
1 # Create a type 'X' with all permissions
2 insert into account_types
3 values ('x', 'mail,groups,forums,list,search,portal');
4
5 # Insert all existing accounts
6 insert into accounts
7 select u.user_id AS uid, hruid AS hruid, 'x' AS type,
8 perms = 'admin' AS is_admin,
9 IF(perms = 'admin' or perms = 'user', 'active', perms) AS state,
10 IF(LENGTH(password) = 40, password, NULL) AS password,
11 IF(LENGTH(q.core_rss_hash) > 0, q.core_rss_hash, NULL) AS token,
12 IF(LENGTH(smtppass) = 0, NULL, smtppass) AS weak_password,
13 date_ins AS registration_date,
14 IF(FIND_IN_SET('watch', flags), 'watch', '') AS flags,
15 IF(LENGTH(comment) > 0, comment, NULL) AS comment,
16 CONCAT(prenom, ' ', IF (nom_usage != '' and nom_usage IS NOT NULL, nom_usage, nom)) AS full_name,
17 prenom AS display_name,
18 IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
19 IF(q.core_mail_fmt = 'html', 'html', 'text') AS email_format,
20 q.skin AS skin,
21 q.last_version AS last_version
22 from auth_user_md5 as u
23 left join auth_user_quick as q on (q.user_id = u.user_id)
24 where hruid is not null;
25
26 # Insert carnet-relative data
27 insert into watch
28 select user_id as uid, watch_flags as flags, watch_last as last
29 from auth_user_quick;
30
31 # Insert all existing profiles
32 insert into profiles
33 select user_id AS pid, hruid AS hrpid, matricule AS xorg_id,
34 matricule_ax AS ax_id, naissance AS birthdate, naissance_ini AS birthdate_ref
35 from auth_user_md5
36 where hruid is not null;
37
38 # Add associations account <-> profile
39 insert into account_profiles
40 select user_id AS uid, user_id AS pid, 'owner' AS perms
41 from auth_user_md5
42 where hruid is not null;
43
44 # Update banana last_seen timetamp
45 update forum_profiles as fp
46 inner join auth_user_quick as q ON (q.user_id = fp.uid)
47 set fp.uid = fp.uid, fp.tree_unread = fp.tree_unread, fp.tree_read = fp.tree_read,
48 fp.last_seen = q.banana_last;
49
50 insert ignore into forum_profiles (uid, last_seen)
51 select user_id as uid, banana_last as last_seen
52 from auth_user_quick
53 where banana_last >= DATE_SUB(NOW(), INTERVAL 6 MONTH);
54
55 # vim:set syntax=mysql: