-- ============================================ -- Migration 001 — Backoffice complet -- Portfolio Tony AVERTY -- ============================================ -- Usage : mysql -u root -p portfoliotony < 001_backoffice.sql -- (remplacer "portfoliotony" par le nom réel de ta base) -- ============================================ -- ── Administrateurs ─────────────────────────────────────── -- Le mot de passe est créé via setup.php (hash bcrypt) CREATE TABLE IF NOT EXISTS admins ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(100) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB; -- ── Messages du formulaire de contact ───────────────────── CREATE TABLE IF NOT EXISTS contact_messages ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, sender_name VARCHAR(255) NOT NULL, sender_email VARCHAR(255) NOT NULL, subject VARCHAR(255) DEFAULT NULL, message TEXT NOT NULL, is_read TINYINT(1) NOT NULL DEFAULT 0, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_msg_read (is_read), INDEX idx_msg_date (created_at) ) ENGINE=InnoDB; -- ── Réponses aux messages (thread email backoffice) ──────── CREATE TABLE IF NOT EXISTS message_replies ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, message_id INT UNSIGNED NOT NULL, reply_text TEXT NOT NULL, sent_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_replies_msg (message_id) ) ENGINE=InnoDB; -- ── Rate limiting (anti-spam / brute force) ─────────────── CREATE TABLE IF NOT EXISTS rate_limits ( id INT AUTO_INCREMENT PRIMARY KEY, action VARCHAR(64) NOT NULL, ip VARCHAR(45) NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, INDEX idx_action_ip_time (action, ip, created_at) ) ENGINE=InnoDB; -- ── Projets (portfolio) ─────────────────────────────────── CREATE TABLE IF NOT EXISTS projects ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL UNIQUE, short_description VARCHAR(500) DEFAULT NULL, full_description TEXT DEFAULT NULL, image VARCHAR(500) DEFAULT NULL, badge ENUM('production', 'development') NOT NULL DEFAULT 'development', technologies TEXT DEFAULT NULL, project_url VARCHAR(500) DEFAULT NULL, status ENUM('published', 'draft') NOT NULL DEFAULT 'draft', display_order INT UNSIGNED NOT NULL DEFAULT 0, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_projects_status (status), INDEX idx_projects_order (display_order) ) ENGINE=InnoDB; -- ── Tracking des visites ────────────────────────────────── CREATE TABLE IF NOT EXISTS visits ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, ip_hash VARCHAR(64) NOT NULL, session_id VARCHAR(64) NOT NULL, page VARCHAR(500) NOT NULL DEFAULT '/', referrer VARCHAR(500) DEFAULT NULL, device_type ENUM('desktop', 'mobile', 'tablet') NOT NULL DEFAULT 'desktop', duration_s INT UNSIGNED DEFAULT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_visits_date (created_at), INDEX idx_visits_session (session_id), INDEX idx_visits_page (page(100)) ) ENGINE=InnoDB; -- ── Clics sur les projets ───────────────────────────────── CREATE TABLE IF NOT EXISTS project_clicks ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, project_id INT UNSIGNED NOT NULL, ip_hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_clicks_project (project_id), INDEX idx_clicks_date (created_at) ) ENGINE=InnoDB; -- ── Services (éditable depuis le backoffice) ────────────── CREATE TABLE IF NOT EXISTS services ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, icon VARCHAR(10) NOT NULL DEFAULT '🚀', title VARCHAR(255) NOT NULL, description TEXT NOT NULL, display_order INT UNSIGNED NOT NULL DEFAULT 0, is_active TINYINT(1) NOT NULL DEFAULT 1, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_services_order (display_order) ) ENGINE=InnoDB; -- ── Contenu du site (clé/valeur) ────────────────────────── CREATE TABLE IF NOT EXISTS site_content ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, content_key VARCHAR(100) NOT NULL UNIQUE, content_value MEDIUMTEXT DEFAULT NULL, content_type ENUM('text', 'textarea', 'html') NOT NULL DEFAULT 'text', label VARCHAR(255) NOT NULL, section VARCHAR(100) NOT NULL DEFAULT 'general', updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX idx_content_section (section) ) ENGINE=InnoDB; -- ── Paramètres globaux ──────────────────────────────────── CREATE TABLE IF NOT EXISTS site_settings ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, setting_key VARCHAR(100) NOT NULL UNIQUE, setting_value TEXT DEFAULT NULL, label VARCHAR(255) NOT NULL DEFAULT '', updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB; -- ── Tentatives de connexion (brute force) ───────────────── CREATE TABLE IF NOT EXISTS login_attempts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(45) NOT NULL, username VARCHAR(100) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_attempts_ip_date (ip, created_at) ) ENGINE=InnoDB; -- ── Logs des actions admin ──────────────────────────────── CREATE TABLE IF NOT EXISTS admin_logs ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, admin_id INT UNSIGNED DEFAULT NULL, username VARCHAR(100) DEFAULT NULL, action VARCHAR(100) NOT NULL, detail TEXT DEFAULT NULL, ip VARCHAR(45) NOT NULL, success TINYINT(1) NOT NULL DEFAULT 1, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_logs_date (created_at), INDEX idx_logs_admin (admin_id) ) ENGINE=InnoDB; -- ── Données par défaut : Services ───────────────────────── INSERT IGNORE INTO services (icon, title, description, display_order) VALUES ('🌐', 'Site vitrine & portfolio', 'Un site professionnel qui reflète votre activité et donne envie de vous contacter. Design soigné, contenu structuré, référencement local intégré.', 1), ('🛒', 'E-commerce & boutique en ligne', 'De la boutique simple au catalogue complet, avec paiement sécurisé, gestion des stocks et interface admin intuitive.', 2), ('⚙️', 'Application web sur mesure', 'Outils métiers, espaces clients, tableaux de bord, automatisations — développés exactement pour votre usage, pas plus, pas moins.', 3), ('🔍', 'SEO & optimisation', 'Audit, structure, contenu et vitesse optimisés pour que Google vous trouve — et surtout, vos clients locaux aussi.', 4), ('🔧', 'Maintenance & évolution', 'Mises à jour, corrections, nouvelles fonctionnalités — votre site reste en bonne santé et évolue avec votre activité.', 5), ('📱', 'Refonte & modernisation', 'Votre site est vieillissant ? Je le remets à niveau : design, performance, responsive et standards modernes.', 6); -- ── Données par défaut : Contenu ────────────────────────── INSERT IGNORE INTO site_content (content_key, content_value, content_type, label, section) VALUES -- SEO ('seo_title', 'Tony AVERTY — Développeur Web Freelance | Sites sur mesure & Applications', 'text', 'Balise