Use last version of the core.
[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 date_ins AS registration_date,
13 IF(FIND_IN_SET('watch', flags), 'watch', '') AS flags,
14 IF(LENGTH(comment) > 0, comment, NULL) AS comment,
15 CONCAT(prenom, ' ', IF (nom_usage != '' and nom_usage IS NOT NULL, nom_usage, nom)) AS full_name,
16 prenom AS display_name,
17 IF(FIND_IN_SET('femme', flags), 'female', 'male') AS sex,
18 IF(q.core_mail_fmt = 'html', 'html', 'text') AS email_format,
19 q.skin AS skin
20 from auth_user_md5 as u
21 left join auth_user_quick as q on (q.user_id = u.user_id)
22 where hruid is not null;
23
24 # Insert all existing profiles
25 insert into profiles
26 select user_id AS pid, hruid AS hrpid, matricule AS xorg_id,
27 matricule_ax AS ax_id, naissance AS birthdate, naissance_ini AS birthdate_ref
28 from auth_user_md5
29 where hruid is not null;
30
31 # Add associations account <-> profile
32 insert into account_profiles
33 select user_id AS uid, user_id AS pid, 'owner' AS perms
34 from auth_user_md5
35 where hruid is not null;
36
37 # Update banana last_seen timetamp
38 update forum_profiles as fp
39 inner join auth_user_quick as q ON (q.user_id = fp.uid)
40 set fp.uid = fp.uid, fp.tree_unread = fp.tree_unread, fp.tree_read = fp.tree_read,
41 fp.last_seen = q.banana_last;
42
43 insert ignore into forum_profiles (uid, last_seen)
44 select user_id as uid, banana_last as last_seen
45 from auth_user_quick
46 where banana_last >= DATE_SUB(NOW(), INTERVAL 6 MONTH);
47
48 # vim:set syntax=mysql: