No more auth_user_ in lists and xnetlists.
[platal.git] / upgrade / account / 99_insertion.sql
CommitLineData
81ef0a18 1# Create a type 'X' with all permissions
6457ddb4 2insert into account_types
cb8a8977
FB
3 values ('x', 'mail,groups,forums,list,search,portal'),
4 ('xnet', 'groups');
5
6457ddb4 6
81ef0a18 7# Insert all existing accounts
6457ddb4
FB
8insert into accounts
9 select u.user_id AS uid, hruid AS hruid, 'x' AS type,
10 perms = 'admin' AS is_admin,
11 IF(perms = 'admin' or perms = 'user', 'active', perms) AS state,
12 IF(LENGTH(password) = 40, password, NULL) AS password,
c67ba12a 13 IF(LENGTH(q.core_rss_hash) > 0, q.core_rss_hash, NULL) AS token,
0511895d 14 IF(LENGTH(smtppass) = 0, NULL, smtppass) AS weak_password,
6457ddb4
FB
15 date_ins AS registration_date,
16 IF(FIND_IN_SET('watch', flags), 'watch', '') AS flags,
17 IF(LENGTH(comment) > 0, comment, NULL) AS comment,
cb8a8977 18 NULL as email,
6457ddb4
FB
19 CONCAT(prenom, ' ', IF (nom_usage != '' and nom_usage IS NOT NULL, nom_usage, nom)) AS full_name,
20 prenom AS display_name,
21 IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
0907974b 22 IF(q.core_mail_fmt = 'html', 'html', 'text') AS email_format,
0511895d
FB
23 q.skin AS skin,
24 q.last_version AS last_version
6457ddb4
FB
25 from auth_user_md5 as u
26 left join auth_user_quick as q on (q.user_id = u.user_id)
27 where hruid is not null;
28
0511895d
FB
29# Insert carnet-relative data
30insert into watch
31 select user_id as uid, watch_flags as flags, watch_last as last
32 from auth_user_quick;
33
c1e98576
FB
34# Insert carvas
35insert into carvas
36 select user_id, redirecturl
37 from auth_user_quick
38 where LENGTH(redirecturl) > 0;
39
81ef0a18
FB
40# Insert all existing profiles
41insert into profiles
3cb24c05
FB
42 select u.user_id AS pid, u.hruid AS hrpid, u.matricule AS xorg_id,
43 u.matricule_ax AS ax_id, u.naissance AS birthdate, u.naissance_ini AS birthdate_ref,
44 IF(u.deces = 0, NULL, u.deces) AS deathdate,
94b72319 45 IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
4e426a09
FB
46 IF(u.section = 0, NULL, u.section) AS section,
47 IF(LENGTH(u.cv) > 0, u.cv, NULL) AS cv,
3cb24c05 48 IF(LENGTH(q.profile_freetext) > 0, q.profile_freetext, NULL) AS freetext,
4e426a09
FB
49 IF(q.profile_freetext_pub = 'public', 'public', 'private') AS freetext_pub,
50 IF(q.profile_medals_pub = 'public', 'public', 'private') AS medals_pub,
51 IF(q.emails_alias_pub = 'public', 'public', 'private') AS alias_pub,
52 u.nationalite AS nationality1, u.nationalite2 AS nationality2,
53 u.nationalite3 AS nationality3, u.date AS last_change
3cb24c05
FB
54 from auth_user_md5 AS u
55 left join auth_user_quick AS q ON (u.user_id = q.user_id)
56 where u.hruid is not null;
81ef0a18
FB
57
58# Add associations account <-> profile
6457ddb4
FB
59insert into account_profiles
60 select user_id AS uid, user_id AS pid, 'owner' AS perms
61 from auth_user_md5
62 where hruid is not null;
63
7d15f750
FB
64# Update banana last_seen timetamp
65 update forum_profiles as fp
66inner join auth_user_quick as q ON (q.user_id = fp.uid)
67 set fp.uid = fp.uid, fp.tree_unread = fp.tree_unread, fp.tree_read = fp.tree_read,
68 fp.last_seen = q.banana_last;
69
70insert ignore into forum_profiles (uid, last_seen)
71 select user_id as uid, banana_last as last_seen
72 from auth_user_quick
73 where banana_last >= DATE_SUB(NOW(), INTERVAL 6 MONTH);
74
58a4e6bb
FB
75# Mail storage has been moved out of account settings
76insert into email_options
77 select user_id as uid, mail_storage as storage
78 from auth_user_md5;
79
6457ddb4 80# vim:set syntax=mysql: