Fix import scripts.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Feb 2010 11:53:14 +0000 (12:53 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 21 Feb 2010 11:53:14 +0000 (12:53 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
21 files changed:
upgrade/account/00_account.sql
upgrade/account/01_profiles.sql
upgrade/account/02_carnet.sql
upgrade/account/03_carva.sql
upgrade/account/04_emails.sql
upgrade/account/99_insertion.sql
upgrade/account/copy_tables.php
upgrade/account/update.sh
upgrade/inc/pervasive.sh
upgrade/newdirectory-0.0.1/00_names.sql
upgrade/newdirectory-0.0.1/02_networking.sql
upgrade/newdirectory-0.0.1/04_telephone.sql
upgrade/newdirectory-0.0.1/06_education.sql
upgrade/newdirectory-0.0.1/07_corps.sql
upgrade/newdirectory-0.0.1/08_nationalities.sql
upgrade/newdirectory-0.0.1/09_education.sql
upgrade/newdirectory-0.0.1/10_promotion.sql
upgrade/newdirectory-0.0.1/11_jobs.sql
upgrade/newdirectory-0.0.1/12_secteurs.sql
upgrade/newdirectory-0.0.1/13_mentoring.sql
upgrade/newdirectory-0.0.1/15_addresses.sql

index f580252..26b0818 100644 (file)
@@ -1,3 +1,4 @@
+DROP TABLE IF EXISTS accounts;
 CREATE TABLE accounts (
   # Account identifier and type
   uid int(6) not null auto_increment,
@@ -34,6 +35,7 @@ CREATE TABLE accounts (
   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 '',
@@ -41,6 +43,7 @@ CREATE TABLE account_types (
   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,
index 96c0f85..cbf5125 100644 (file)
@@ -1,3 +1,4 @@
+drop table if exists profiles;
 create table profiles (
   # Profile identifiers
   pid int(6) not null auto_increment,
index ec903bf..aad0369 100644 (file)
@@ -1,3 +1,4 @@
+drop table if exists watch;
 create table watch (
   uid   int(6) not null,
   flags set('contacts', 'mail') not null default 'contacts',
index b3a40cd..9768750 100644 (file)
@@ -1,3 +1,4 @@
+drop table if exists carvas;
 create table carvas (
   uid int(6) not null,
   url varchar(255) not null,
index 4036f17..70b4736 100644 (file)
@@ -1,3 +1,4 @@
+drop table if exists email_options;
 create table email_options (
   uid int(6) not null,
   storage set('imap', 'googleapps') not null default '',
index 9d9b18f..10a2fe4 100644 (file)
@@ -60,8 +60,8 @@ insert into profiles
             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;
index 76aecb3..027b3e7 100755 (executable)
 
 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);
@@ -69,14 +76,13 @@ copyTable('#x4dat#.newsletter_art', 'newsletter_art');
 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');
 
@@ -113,7 +119,7 @@ copyTable('#x4dat#.skins', 'skins');
 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');
@@ -121,6 +127,7 @@ copyTable('#x4dat#.perte_pass', 'account_lost_passwords');
 
 copyTable('#x4dat#.geoloc_pays', 'geoloc_pays');
 
+copyTable('#x4dat#.emails', 'emails');
 copyTable('#x4dat#.aliases', 'aliases');
 copyTable('#x4dat#.virtual', 'virtual');
 copyTable('#x4dat#.virtual_domains', 'virtual_domains');
@@ -128,7 +135,8 @@ copyTable('#x4dat#.virtual_redirect', 'virtual_redirect');
 
 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:
 ?>
index c105507..a322ed9 100644 (file)
@@ -3,10 +3,16 @@
 . ../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"
@@ -14,21 +20,21 @@ 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"
 
 ###########################################################
index f2eebd0..ede0942 100755 (executable)
@@ -5,16 +5,16 @@ MYSQL='mysql -u admin '
 
 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() {
index 0fcc2b6..17cb415 100644 (file)
@@ -62,12 +62,13 @@ INSERT INTO  profile_name_enum (name, flags, explanations, type, score)
 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)';
 
index 0ef0ddc..f18e05d 100644 (file)
@@ -1,4 +1,7 @@
-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',
@@ -7,6 +10,7 @@ CREATE TABLE IF NOT EXISTS `profile_networking_enum` (
     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',
index dc09189..00609e5 100644 (file)
@@ -1,4 +1,6 @@
-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',
index bd0c9ab..631941c 100644 (file)
@@ -1,11 +1,17 @@
-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,
@@ -14,13 +20,13 @@ CREATE TABLE IF NOT EXISTS profile_education_degree_enum (
   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,
@@ -30,7 +36,7 @@ CREATE TABLE IF NOT EXISTS profile_education_enum (
   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,
index 0487410..49ee5e7 100644 (file)
@@ -1,3 +1,7 @@
+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,
index 937579d..439ba60 100644 (file)
@@ -1,4 +1,5 @@
 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,
index 6b4b7a6..ffb9063 100644 (file)
@@ -208,8 +208,10 @@ WHERE name = 'INSA Rouen';
 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';
 
@@ -522,7 +524,7 @@ WHERE name = 'IHEDN';
 
 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
index de629b4..5cd2066 100644 (file)
@@ -1,6 +1,6 @@
 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");
 
index 58896bc..cd359d9 100644 (file)
@@ -1,6 +1,6 @@
 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 '',
@@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS profile_job_enum (
 
 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,
index e8065b1..77ecf36 100644 (file)
@@ -1,15 +1,15 @@
 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,
@@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS profile_job_subsector_enum (
 
 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,
@@ -30,12 +30,12 @@ CREATE TABLE IF NOT EXISTS profile_job_subsubsector_enum (
 
 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;
 
 
index 9e392fd..4aa967c 100644 (file)
@@ -2,18 +2,17 @@ DROP TABLE IF EXISTS profile_mentor;
 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),
@@ -24,7 +23,7 @@ INSERT INTO  profile_mentor_country (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,
index 8a95d0a..a529d59 100644 (file)
@@ -1,6 +1,6 @@
 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',
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS profile_addresses (
 
 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,', ''),
@@ -44,7 +44,8 @@ INSERT INTO  profile_addresses (pid, id, postalCode, updateTime, pub, comment, l
                     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,
@@ -73,14 +74,18 @@ UPDATE  geoloc_pays
    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,
@@ -91,6 +96,7 @@ CREATE TABLE IF NOT EXISTS geoloc_administrativeareas (
   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,
@@ -102,6 +108,7 @@ CREATE TABLE IF NOT EXISTS geoloc_subadministrativeareas (
   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,
@@ -113,4 +120,5 @@ CREATE TABLE IF NOT EXISTS geoloc_localities (
   INDEX(country)
 ) ENGINE=InnoDB, CHARSET=utf8;
 
+DROP TABLE geoloc_pays;
 -- vim:set syntax=mysql: