-- Suppression des écrits qui n'existent pas
DELETE e FROM ecrits e LEFT JOIN ecrits_html h ON h.id = e.id WHERE h.id IS NULL ;
DELETE h FROM ecrits_html h LEFT JOIN ecrits e ON h.id = e.id WHERE e.id IS NULL ;

-- Même chose sur les forums
DELETE f FROM forums f LEFT JOIN forums_textes t ON t.id = f.id WHERE t.id IS NULL ;
DELETE t FROM forums_textes t LEFT JOIN forums f ON t.id = f.id WHERE f.id IS NULL ;

-- Changer la taille du champ mot de passe
ALTER TABLE `membres` CHANGE `password` `password` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';

-- Changer l'encodage
ALTER TABLE `membres` CHANGE `email` `email` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';
ALTER TABLE `membres` CHANGE `ip` `ip` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL;
ALTER TABLE `membres` CHANGE `courant` `courant` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL;
ALTER TABLE `membres` CHANGE `timezone` `timezone` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';
ALTER TABLE `membres` CHANGE `ip_inscription` `ip_inscription` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '';
ALTER TABLE `membres` CHANGE `session_id` `session_id` VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL;

ALTER TABLE `user_secret_keys` CHANGE `key` `key` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `user_secret_keys` CHANGE `action` `action` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `user_secret_keys` CHANGE `content` `content` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ALTER TABLE `ecrits_html` CHANGE `texte` `texte` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums_textes` CHANGE `texte` `texte` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `journaux` CHANGE `texte` `texte` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ALTER TABLE `abonnements` CHANGE `journal` `journal` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `abonnements` CHANGE `email` `email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `abonnements_queue` CHANGE `journal` `journal` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `acces_prives` CHANGE `journal` `journal` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `acces_prives` CHANGE `login` `login` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `acces_prives` CHANGE `password` `password` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `ecrits` CHANGE `journal` `journal` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `ecrits` CHANGE `titre` `titre` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `ecrits` CHANGE `ip` `ip` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `ecrits` CHANGE `uri` `uri` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `journal` `journal` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `nom` `nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `contact` `contact` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `titre` `titre` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `ip` `ip` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `forums` CHANGE `uri` `uri` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `journaux` CHANGE `id` `id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `journaux` CHANGE `titre` `titre` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `journaux` CHANGE `visuel` `visuel` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Changer le character set
ALTER TABLE abonnements CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE abonnements_queue CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE acces_prives CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ecrits CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ecrits_html CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE forums CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE forums_textes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE journaux CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE membres CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE user_secret_keys CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

REPAIR TABLE abonnements;
OPTIMIZE TABLE abonnements;

REPAIR TABLE abonnements_queue;
OPTIMIZE TABLE abonnements_queue;

REPAIR TABLE acces_prives;
OPTIMIZE TABLE acces_prives;

REPAIR TABLE ecrits;
OPTIMIZE TABLE ecrits;

REPAIR TABLE ecrits_html;
OPTIMIZE TABLE ecrits_html;

REPAIR TABLE forums;
OPTIMIZE TABLE forums;

REPAIR TABLE forums_textes;
OPTIMIZE TABLE forums_textes;

REPAIR TABLE journaux;
OPTIMIZE TABLE journaux;

REPAIR TABLE membres;
OPTIMIZE TABLE membres;

REPAIR TABLE user_secret_keys;
OPTIMIZE TABLE user_secret_keys;
