+DROP TABLE IF EXISTS accounts;
CREATE TABLE accounts (
# Account identifier and type
uid int(6) not null auto_increment,
key type (type)
) ENGINE=InnoDB, CHARSET=utf8;
+DROP TABLE IF EXISTS account_types;
CREATE TABLE account_types (
type varchar(16) not null,
perms set('mail', 'groups', 'forums', 'list', 'search', 'portal') default '',
primary key type (type)
) ENGINE=InnoDB, CHARSET=utf8;
+DROP TABLE IF EXISTS account_profiles;
CREATE TABLE account_profiles (
uid int(6) not null,
pid int(6) not null,
+drop table if exists profiles;
create table profiles (
# Profile identifiers
pid int(6) not null auto_increment,
+drop table if exists watch;
create table watch (
uid int(6) not null,
flags set('contacts', 'mail') not null default 'contacts',
+drop table if exists carvas;
create table carvas (
uid int(6) not null,
url varchar(255) not null,
+drop table if exists email_options;
create table email_options (
uid int(6) not null,
storage set('imap', 'googleapps') not null default '',
IF(q.profile_freetext_pub = 'public', 'public', 'private') AS freetext_pub,
IF(q.profile_medals_pub = 'public', 'public', 'private') AS medals_pub,
IF(q.emails_alias_pub = 'public', 'public', 'private') AS alias_pub,
- u.nationalite AS nationality1, u.nationalite2 AS nationality2,
- u.nationalite3 AS nationality3, u.date AS last_change
+ IF(u.nationalite = '' OR u.nationalite IS NULL, NULL, u.nationalite) AS nationality1,
+ NULL AS nationality2, NULL AS nationality3, u.date AS last_change
from #x4dat#.auth_user_md5 AS u
left join #x4dat#.auth_user_quick AS q ON (u.user_id = q.user_id)
where u.hruid is not null;
require('./connect.db.inc.php');
-function copyTable($source, $target)
+$globals->dbuser = 'admin';
+$globals->dbpwd = 'lknjiuhb';
+$globals->debug = 1;
+
+function copyTable($source, $target, $convertToInnoDB = true)
{
XDB::execute('CREATE TABLE ' . $target . '
- LIKE ' . $source . '
- ENGINE = InnoDB');
+ LIKE ' . $source);
+ if ($convertToInnoDB) {
+ XDB::execute('ALTER TABLE ' . $target . '
+ ENGINE = InnoDB');
+ }
XDB::execute('INSERT INTO ' . $target . '
SELECT *
FROM ' . $source);
copyTable('#x4dat#.newsletter_cat', 'newsletter_cat');
copyTable('#x4dat#.newsletter_ins', 'newsletter_ins');
-copyTable('#x4dat#.openid_trusted', 'openid_trusted');
copyTable('#x4dat#.evenements', 'announces');
copyTable('#x4dat#.evenements_photo', 'announce_photos');
copyTable('#x4dat#.evenements_vus', 'announce_read');
-copyTable('#x4dat#.gapps_accounts', 'gapps_accounts');
-copyTable('#x4dat#.gapps_nicknames', 'gapps_nicknames');
+copyTable('#x4dat#.gapps_accounts', 'gapps_accounts', false);
+copyTable('#x4dat#.gapps_nicknames', 'gapps_nicknames', false);
copyTable('#x4dat#.gapps_queue', 'gapps_queue');
copyTable('#x4dat#.gapps_reporting', 'gapps_reporting');
copyTable('#x4dat#.tips', 'tips');
copyTable('#x4dat#.survey_surveys', 'surveys');
-copyTable('#x4dat#.survey_anwsers', 'survey_anwsers');
+copyTable('#x4dat#.survey_answers', 'survey_answers');
copyTable('#x4dat#.survey_votes', 'survey_votes');
copyTable('#x4dat#.watch_profile', 'watch_profile');
copyTable('#x4dat#.geoloc_pays', 'geoloc_pays');
+copyTable('#x4dat#.emails', 'emails');
copyTable('#x4dat#.aliases', 'aliases');
copyTable('#x4dat#.virtual', 'virtual');
copyTable('#x4dat#.virtual_domains', 'virtual_domains');
copyTable('#x4dat#.watch_nonins', 'watch_nonins');
copyTable('#x4dat#.watch_promo', 'watch_promo');
-copyTable('#x4dat#.watch_profile', 'watch_profile');
+
+copyTable('#x4dat#.openid_trusted', 'openid_trusted', false);
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
. ../inc/pervasive.sh
###########################################################
-echo "Setting up new database: target db is $DATABASE, source prefix is $DBPREFIX"
-echo "* press ^D to start import"
+[ "$DATABASE" != "x4dat" ] || die "Cannot target x4dat"
+
+echo "Setting up new database: target db is \"$DATABASE\", source prefix is \"$DBPREFIX\""
+echo "* press ^D to start import (^C to cancel)"
cat
+echo -n "* create database "
+(echo "CREATE DATABASE IF NOT EXISTS $DATABASE;" | $MYSQL) || die "ERROR"
+echo "OK"
+
echo -n "* copying tables "
./copy_tables.php || die "ERROR"
echo "OK"
for sql in ../newdirectory-0.0.1/*.sql
do
echo -n "* running $sql "
- (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE &>/dev/null) || die "ERROR"
+ (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE >/dev/null) || die "ERROR"
echo "OK"
done
for sql in *.sql
do
echo -n "* running $sql "
- (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE &>/dev/null) || die "ERROR"
+ (sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" < $sql | $MYSQL $DATABASE >/dev/null) || die "ERROR"
echo "OK"
done
###########################################################
echo -n "Importing phone numbers "
-./newdirectory-0.0.1/phones.php || die "ERROR"
+../newdirectory-0.0.1/phones.php || die "ERROR"
echo "OK"
###########################################################
set -e
-if [ "$UID" != 0 ]; then
- echo "has to be run as root"
- exit 1
-fi
+#if [ "$UID" != 0 ]; then
+# echo "has to be run as root"
+# exit 1
+#fi
if [[ -n "${DBPREFIX}" ]]; then
echo "Using non-default database ${DBPREFIX}x4dat."
fi
-if [[ -n "${DATABASE}" ]]; then
- declare -r DATABASE="${DBPREFIX}x4dat"
+if [[ -z "${DATABASE}" ]]; then
+ DATABASE="${DBPREFIX}x4dat"
fi
function die() {
DROP TABLE IF EXISTS profile_name;
CREATE TABLE IF NOT EXISTS profile_name (
- id TINYINT(2) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id of this name for this user',
+ id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id of this name for this user',
pid INT(11) NOT NULL COMMENT 'id of alumni',
name VARCHAR(255) NOT NULL COMMENT 'name to search for',
particle VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'particle of the name to search for',
typeid TINYINT(2) UNSIGNED NOT NULL COMMENT 'type of name',
PRIMARY KEY (pid, id),
+ KEY (id),
INDEX pid (pid)
) ENGINE=InnoDB, CHARSET=utf8, COMMENT = 'Names of alumni (search table)';
-CREATE TABLE IF NOT EXISTS `profile_networking_enum` (
+DROP TABLE IF EXISTS profile_networking_enum;
+DROP TABLE IF EXISTS profile_networking;
+
+CREATE TABLE `profile_networking_enum` (
`network_type` tinyint unsigned NOT NULL,
`name` varchar(30) NOT NULL,
`icon` varchar(50) NOT NULL COMMENT 'icon filename',
PRIMARY KEY (`network_type`)
) ENGINE=InnoDB, CHARSET=utf8, COMMENT='types of networking addresses';
+
CREATE TABLE IF NOT EXISTS `profile_networking` (
`uid` int NOT NULL COMMENT 'user id',
`nwid` tinyint unsigned NOT NULL COMMENT 'number of the address for the user',
-CREATE TABLE IF NOT EXISTS `profile_phones` (
+DROP TABLE IF EXISTS profile_phones;
+
+CREATE TABLE `profile_phones` (
`uid` smallint unsigned NOT NULL,
`link_type` enum('address', 'pro', 'user') NOT NULL DEFAULT 'user' COMMENT 'type of parent element',
`link_id` tinyint unsigned NOT NULL COMMENT 'id of his parent element',
-CREATE TABLE IF NOT EXISTS profile_education_field_enum (
+DROP TABLE IF EXISTS profile_education_field_enum;
+DROP TABLE IF EXISTS profile_education_degree_enum;
+DROP TABLE IF EXISTS profile_education_degree;
+DROP TABLE IF EXISTS profile_education_enum;
+DROP TABLE IF EXISTS profile_education;
+
+CREATE TABLE profile_education_field_enum (
id INT(2) NOT NULL AUTO_INCREMENT,
field VARCHAR(255) DEFAULT NULL,
PRIMARY KEY(id),
UNIQUE KEY(field)
) ENGINE=InnoDB, CHARSET=utf8;
-CREATE TABLE IF NOT EXISTS profile_education_degree_enum (
+CREATE TABLE profile_education_degree_enum (
id INT(2) NOT NULL AUTO_INCREMENT,
degree VARCHAR(255) DEFAULT NULL,
abbreviation VARCHAR(255) DEFAULT '' NOT NULL,
UNIQUE KEY(degree)
) ENGINE=InnoDB, CHARSET=utf8;
-CREATE TABLE IF NOT EXISTS profile_education_degree (
+CREATE TABLE profile_education_degree (
eduid INT(4) NOT NULL DEFAULT 0,
degreeid INT(2) NOT NULL DEFAULT 0,
PRIMARY KEY(eduid, degreeid)
) ENGINE=InnoDB, CHARSET=utf8;
-CREATE TABLE IF NOT EXISTS profile_education_enum (
+CREATE TABLE profile_education_enum (
id INT(4) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) DEFAULT NULL,
abbreviation VARCHAR(255) DEFAULT '' NOT NULL,
UNIQUE KEY(name)
) ENGINE=InnoDB, CHARSET=utf8;
-CREATE TABLE IF NOT EXISTS profile_education (
+CREATE TABLE profile_education (
id TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
uid INT(11) NOT NULL DEFAULT 0,
eduid INT(4) NOT NULL DEFAULT 0,
+DROP TABLE IF EXISTS profile_corps;
+DROP TABLE IF EXISTS profile_corps_enum;
+DROP TABLE IF EXISTS profile_corps_rank_enum;
+
CREATE TABLE IF NOT EXISTS profile_corps (
uid INT(11) NOT NULL,
original_corpsid INT(4) UNSIGNED NOT NULL DEFAULT 0,
ALTER TABLE geoloc_pays ADD COLUMN license_plate CHAR(4) DEFAULT NULL;
+DROP TABLE IF EXISTS tmp_update_geoloc_pays;
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_update_geoloc_pays (
a2 CHAR(2) DEFAULT NULL,
UPDATE profile_education_enum
SET abbreviation = 'IAE de Paris', name = 'Institut d\'Administration des Entreprises de Paris', url = 'http://iae.univ-paris1.fr/'
WHERE name = 'Institut d\'Administration des Entreprises';
+UPDATE profile_education_enum
SET abbreviation = 'CNSMDP', name = 'Conservatoire National Supérieur de Musique et de Danse de Paris'
WHERE name = 'Conservatoire national supérieur de musique et de danse de Paris';
+UPDATE profile_education_enum
SET name = 'École Normale de Musique de Paris'
WHERE name = 'École normale de musique de Paris';
UPDATE profile_education_enum
SET name = "Centre des Hautes Études de l'Armement", country = 'FR', url ='http://www.chear.defense.gouv.fr/',
-WHERE name = 'CHEAr'
+abbreviation = 'CHEAr'
WHERE name = 'CHEAr';
-- Cleans duplicated entries
INSERT INTO profile_education (id, uid, grad_year, entry_year, eduid, degreeid, flags)
SELECT 100, u.user_id, u.promo_sortie, u.promo, e.id, d.id, 'primary'
- FROM auth_user_md5 AS u
+ FROM #x4dat#.auth_user_md5 AS u
LEFT JOIN profile_education_enum AS e ON (e.abbreviation = "X")
LEFT JOIN profile_education_degree_enum AS d ON (d.degree = "Ingénieur");
DROP TABLE IF EXISTS profile_job_enum;
-CREATE TABLE IF NOT EXISTS profile_job_enum (
+CREATE TABLE profile_job_enum (
id INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL DEFAULT '',
acronym VARCHAR(255) NOT NULL DEFAULT '',
DROP TABLE IF EXISTS profile_job;
-CREATE TABLE IF NOT EXISTS profile_job (
+CREATE TABLE profile_job (
id TINYINT(1) UNSIGNED NOT NULL,
uid INT(11) NOT NULL DEFAULT 0,
jobid INT(6) UNSIGNED NOT NULL DEFAULT 0,
DROP TABLE IF EXISTS profile_job_sector_enum;
-CREATE TABLE IF NOT EXISTS profile_job_sector_enum (
+CREATE TABLE profile_job_sector_enum (
id TINYINT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(256) NOT NULL DEFAULT '',
PRIMARY KEY(id),
- UNIQUE KEY(name)
+ UNIQUE INDEX(name(128))
) ENGINE=InnoDB, CHARSET=utf8;
DROP TABLE IF EXISTS profile_job_subsector_enum;
-CREATE TABLE IF NOT EXISTS profile_job_subsector_enum (
+CREATE TABLE profile_job_subsector_enum (
id TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
sectorid TINYINT(2) UNSIGNED NOT NULL,
flags SET('optgroup') DEFAULT '' NOT NULL,
DROP TABLE IF EXISTS profile_job_subsubsector_enum;
-CREATE TABLE IF NOT EXISTS profile_job_subsubsector_enum (
+CREATE TABLE profile_job_subsubsector_enum (
id SMALLINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
sectorid TINYINT(2) UNSIGNED NOT NULL,
subsectorid TINYINT(3) UNSIGNED NOT NULL,
DROP TABLE IF EXISTS profile_job_alternates;
-CREATE TABLE IF NOT EXISTS profile_job_alternates (
+CREATE TABLE profile_job_alternates (
id TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
subsubsectorid SMALLINT(3) UNSIGNED NOT NULL,
name VARCHAR(256) NOT NULL DEFAULT '',
PRIMARY KEY(id, subsubsectorid),
- UNIQUE KEY(name)
+ UNIQUE INDEX(name(128))
) ENGINE=InnoDB, CHARSET=utf8;
DROP TABLE IF EXISTS profile_mentor_country;
DROP TABLE IF EXISTS profile_mentor_sector;
-CREATE TABLE IF NOT EXISTS profile_mentor (
+CREATE TABLE profile_mentor (
uid INT(11) NOT NULL DEFAULT 0,
expertise TEXT NOT NULL,
- PRIMARY KEY (uid),
- FULLTEXT INDEX (expertise)
+ PRIMARY KEY (uid)
) ENGINE=InnoDB, CHARSET=utf8;
INSERT INTO profile_mentor (uid, expertise)
SELECT uid, expertise
FROM #x4dat#.mentor;
-CREATE TABLE IF NOT EXISTS profile_mentor_country (
+CREATE TABLE profile_mentor_country (
uid INT(11) NOT NULL DEFAULT 0,
country CHAR(2) NOT NULL DEFAULT "FR",
PRIMARY KEY (uid, country),
SELECT uid, pid
FROM #x4dat#.mentor_pays;
-CREATE TABLE IF NOT EXISTS profile_mentor_sector (
+CREATE TABLE profile_mentor_sector (
uid INT(11) NOT NULL DEFAULT 0,
sectorid TINYINT(2) UNSIGNED NOT NULL,
subsectorid TINYINT(3) UNSIGNED NOT NULL,
DROP TABLE IF EXISTS profile_addresses;
-CREATE TABLE IF NOT EXISTS profile_addresses (
+CREATE TABLE profile_addresses (
pid INT(11) DEFAULT NULL,
jobid INT(6) UNSIGNED DEFAULT NULL,
type ENUM('home','job','hq') NOT NULL DEFAULT 'home',
INSERT INTO profile_addresses (pid, id, postalCode, updateTime, pub, comment, latitude, longitude, countryId,
type, flags)
- SELECT uid, adrid, postcode, datemaj, pub, comment, glat, glng, country,
+ SELECT uid, adrid, postcode, datemaj, pub, NULL, glat, glng, country,
IF(FIND_IN_SET('pro', 'statut'), 'job', 'home'),
CONCAT(IF(FIND_IN_SET('res-secondaire', 'statut'), 'secondary,', ''),
IF(FIND_IN_SET('courrier', 'statut'), 'mail,', ''),
IF(FIND_IN_SET('temporaire', 'statut'), 'temporary', ''))
FROM #x4dat#.adresses;
-CREATE TABLE IF NOT EXISTS geoloc_countries (
+DROP TABLE IF EXISTS geoloc_countries;
+CREATE TABLE geoloc_countries (
iso_3166_1_a2 CHAR(2) NOT NULL,
iso_3166_1_a3 CHAR(3) NOT NULL,
iso_3166_1_num SMALLINT(3) UNSIGNED NOT NULL,
SET n3 = 807
WHERE a2 = "MK";
+UPDATE geoloc_pays
+ SET n3 = 232
+ WHERE a2 = "ER";
+
INSERT INTO geoloc_countries (iso_3166_1_a2, iso_3166_1_a3, iso_3166_1_num, worldRegion,
countryFR, country, capital, nationalityFR,
phonePrefix, phoneFormat, licensePlate)
SELECT a2, a3, n3, worldrgn, pays, country, capital, nat, phoneprf, phoneformat, license_plate
FROM geoloc_pays;
-DROP TABLE geoloc_pays;
-CREATE TABLE IF NOT EXISTS geoloc_administrativeareas (
+DROP TABLE IF EXISTS geoloc_administrativeareas;
+CREATE TABLE geoloc_administrativeareas (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
country CHAR(2) NOT NULL,
INDEX(country)
) ENGINE=InnoDB, CHARSET=utf8;
+DROP TABLE IF EXISTS geoloc_subadministrativeareas;
CREATE TABLE IF NOT EXISTS geoloc_subadministrativeareas (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
INDEX(country)
) ENGINE=InnoDB, CHARSET=utf8;
+DROP TABLE IF EXISTS geoloc_localities;
CREATE TABLE IF NOT EXISTS geoloc_localities (
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
INDEX(country)
) ENGINE=InnoDB, CHARSET=utf8;
+DROP TABLE geoloc_pays;
-- vim:set syntax=mysql: