🗄️ Générateur de Schéma SQL

Structure réelle de la base de données - Généré le : 2026-02-04 22:39:03

📊 Tables (8)
8
Tables
78
Colonnes
27
Index
1
Clés étrangères
📋 appointment_logs 6 colonnes
  • id bigint PK
  • booking_id char(26) INDEX
  • level enum('INFO','WARN','ERROR')
  • message text
  • context json
  • created_at datetime
📋 appointments 17 colonnes
  • id bigint PK
  • booking_id char(26) UNIQUE
  • calendar_event_id varchar(255) INDEX
  • service_id varchar(32)
  • customer_id bigint INDEX FK
  • start_datetime datetime INDEX
  • end_datetime datetime
  • status enum('PENDING','CONFIRMED','CANCELED','FAILED')
  • appointment_mode enum('Agence','Visio','Téléphone') INDEX
  • client_message text
  • calendar_sync_status enum('PENDING','SYNCED','FAILED')
  • cancellation_token varchar(512)
  • confirmation_token varchar(64) INDEX
  • confirmation_token_expires_at datetime INDEX
  • created_at datetime
  • updated_at datetime
  • ical_uid varchar(255) UNIQUE
Relations :
  • customer_id → customers.id
📋 availability_cache 8 colonnes
  • id int PK
  • source varchar(50) INDEX
  • contact_email varchar(255)
  • slot_datetime datetime
  • duration_minutes int
  • is_available tinyint(1)
  • updated_at timestamp
  • sync_batch_id varchar(100)
📋 customers 6 colonnes
  • id bigint PK
  • email varchar(255) UNIQUE
  • phone varchar(50)
  • first_name varchar(100)
  • last_name varchar(100)
  • created_at datetime
📋 resources 10 colonnes
  • id bigint unsigned PK
  • display_name varchar(150)
  • email varchar(255) INDEX
  • provider enum('ms365','google') INDEX
  • calendar_id varchar(256)
  • timezone varchar(50)
  • business_hours json
  • active tinyint(1)
  • created_at timestamp
  • updated_at timestamp
📋 sync_logs 20 colonnes
  • id int PK
  • sync_type varchar(50) INDEX
  • sync_action varchar(50)
  • sync_batch_id varchar(100) INDEX
  • contact_email varchar(255) INDEX
  • details json
  • items_processed int
  • items_success int
  • items_failed int
  • started_at timestamp
  • completed_at timestamp
  • duration_seconds int
  • status enum('pending','running','completed','failed','partial') INDEX
  • message text
  • error_details json
  • environment varchar(50)
  • user_agent varchar(255)
  • source_ip varchar(45)
  • created_at timestamp INDEX
  • updated_at timestamp
📋 sync_state 6 colonnes
  • id int PK
  • provider varchar(16)
  • resource varchar(128)
  • sync_cursor varchar(256)
  • subscription_id varchar(256)
  • expires_at datetime
📋 webhook_events 5 colonnes
  • id bigint PK
  • provider varchar(16)
  • event_type varchar(64)
  • payload json
  • received_at datetime
💾 Code SQL
CREATE TABLE `appointment_logs` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `booking_id` char(26) NOT NULL,
  `level` ENUM('INFO','WARN','ERROR') NOT NULL,
  `message` TEXT NOT NULL,
  `context` json DEFAULT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_logs_booking` (`booking_id`)
) ENGINE=InnoDB AUTO_INCREMENT=573 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `appointments` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `booking_id` char(26) NOT NULL,
  `calendar_event_id` VARCHAR(255) DEFAULT NULL,
  `service_id` VARCHAR(32) NOT NULL,
  `customer_id` bigint NOT NULL,
  `start_datetime` DATETIME NOT NULL,
  `end_datetime` DATETIME NOT NULL,
  `status` ENUM('PENDING','CONFIRMED','CANCELED','FAILED') NOT NULL DEFAULT 'PENDING',
  `appointment_mode` ENUM('Agence','Visio','Téléphone') DEFAULT 'Agence' COMMENT 'Mode de rendez-vous: Agence (présentiel), Visio (visioconférence), Téléphone',
  `client_message` TEXT COMMENT 'Message optionnel laissé par le client lors de la réservation',
  `calendar_sync_status` ENUM('PENDING','SYNCED','FAILED') DEFAULT 'PENDING',
  `cancellation_token` VARCHAR(512) DEFAULT NULL,
  `confirmation_token` VARCHAR(64) DEFAULT NULL,
  `confirmation_token_expires_at` DATETIME DEFAULT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` DATETIME DEFAULT NULL,
  `ical_uid` VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_appt_booking` (`booking_id`),
  UNIQUE KEY `uq_ical_uid` (`ical_uid`),
  KEY `fk_appt_customer` (`customer_id`),
  KEY `idx_appt_time` (`start_datetime`,`end_datetime`),
  KEY `idx_appt_calendar` (`calendar_event_id`),
  KEY `idx_confirmation_token` (`confirmation_token`),
  KEY `idx_confirmation_expires` (`confirmation_token_expires_at`),
  KEY `idx_appointment_mode` (`appointment_mode`),
  CONSTRAINT `fk_appt_customer` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=215 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `availability_cache` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `source` VARCHAR(50) NOT NULL DEFAULT 'M365',
  `contact_email` VARCHAR(255) DEFAULT NULL,
  `slot_datetime` DATETIME NOT NULL,
  `duration_minutes` INT NOT NULL DEFAULT '30',
  `is_available` tinyint(1) NOT NULL DEFAULT '1',
  `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `sync_batch_id` VARCHAR(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_slot` (`source`,`slot_datetime`,`duration_minutes`)
) ENGINE=InnoDB AUTO_INCREMENT=5294 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `customers` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(255) NOT NULL,
  `phone` VARCHAR(50) DEFAULT NULL,
  `first_name` VARCHAR(100) DEFAULT NULL,
  `last_name` VARCHAR(100) DEFAULT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_customers_email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=515 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `resources` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `display_name` VARCHAR(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `provider` ENUM('ms365','google') COLLATE utf8mb4_unicode_ci NOT NULL,
  `calendar_id` VARCHAR(256) COLLATE utf8mb4_unicode_ci NOT NULL,
  `timezone` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Europe/Brussels',
  `business_hours` json DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_provider_calendar` (`provider`,`calendar_id`),
  KEY `idx_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `sync_logs` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `sync_type` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Type: M365, availability_cache, etc.',
  `sync_action` VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Action: start, end, error, etc.',
  `sync_batch_id` VARCHAR(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Batch ID pour regrouper les opérations',
  `contact_email` VARCHAR(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Email du contact concerné',
  `details` json DEFAULT NULL COMMENT 'Détails spécifiques au sync (events, slots, etc.)',
  `items_processed` INT DEFAULT '0' COMMENT 'Nombre d''éléments traités',
  `items_success` INT DEFAULT '0' COMMENT 'Nombre d''éléments réussis',
  `items_failed` INT DEFAULT '0' COMMENT 'Nombre d''éléments échoués',
  `started_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Début de l''opération',
  `completed_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Fin de l''opération',
  `duration_seconds` INT DEFAULT NULL COMMENT 'Durée en secondes',
  `status` ENUM('pending','running','completed','failed','partial') COLLATE utf8mb4_unicode_ci DEFAULT 'pending',
  `message` TEXT COLLATE utf8mb4_unicode_ci COMMENT 'Message détaillé ou erreur',
  `error_details` json DEFAULT NULL COMMENT 'Détails des erreurs',
  `environment` VARCHAR(50) COLLATE utf8mb4_unicode_ci DEFAULT 'local' COMMENT 'alpha, beta, production, local',
  `user_agent` VARCHAR(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'User agent de la requête',
  `source_ip` VARCHAR(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'IP source',
  `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_sync_type` (`sync_type`),
  KEY `idx_sync_batch` (`sync_batch_id`),
  KEY `idx_contact_email` (`contact_email`),
  KEY `idx_status` (`status`),
  KEY `idx_created_at` (`created_at`),
  KEY `idx_sync_type_date` (`sync_type`,`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=154 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Logging des synchronisations M365 et availability_cache';

CREATE TABLE `sync_state` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `provider` VARCHAR(16) NOT NULL,
  `resource` VARCHAR(128) NOT NULL,
  `sync_cursor` VARCHAR(256) DEFAULT NULL,
  `subscription_id` VARCHAR(256) DEFAULT NULL,
  `expires_at` DATETIME DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE `webhook_events` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `provider` VARCHAR(16) NOT NULL,
  `event_type` VARCHAR(64) NOT NULL,
  `payload` json NOT NULL,
  `received_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;