Import singletons from 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 carvas
32 insert into carvas
33 select user_id, redirecturl
34 from auth_user_quick
35 where LENGTH(redirecturl) > 0;
36
37 # Insert all existing profiles
38 insert into profiles
39 select u.user_id AS pid, u.hruid AS hrpid, u.matricule AS xorg_id,
40 u.matricule_ax AS ax_id, u.naissance AS birthdate, u.naissance_ini AS birthdate_ref,
41 IF(u.deces = 0, NULL, u.deces) AS deathdate,
42 u.date AS last_change,
43 IF(LENGTH(q.profile_freetext) > 0, q.profile_freetext, NULL) AS freetext,
44 q.profile_freetext_pub AS freetext_pub,
45 q.profile_medals_pub AS medals_pub,
46 q.emails_alias_pub AS alias_pub
47 from auth_user_md5 AS u
48 left join auth_user_quick AS q ON (u.user_id = q.user_id)
49 where u.hruid is not null;
50
51 # Add associations account <-> profile
52 insert into account_profiles
53 select user_id AS uid, user_id AS pid, 'owner' AS perms
54 from auth_user_md5
55 where hruid is not null;
56
57 # Update banana last_seen timetamp
58 update forum_profiles as fp
59 inner join auth_user_quick as q ON (q.user_id = fp.uid)
60 set fp.uid = fp.uid, fp.tree_unread = fp.tree_unread, fp.tree_read = fp.tree_read,
61 fp.last_seen = q.banana_last;
62
63 insert ignore into forum_profiles (uid, last_seen)
64 select user_id as uid, banana_last as last_seen
65 from auth_user_quick
66 where banana_last >= DATE_SUB(NOW(), INTERVAL 6 MONTH);
67
68 # Mail storage has been moved out of account settings
69 insert into email_options
70 select user_id as uid, mail_storage as storage
71 from auth_user_md5;
72
73 # vim:set syntax=mysql: