-- -------------------------------------------------------------
-- TablePlus 6.4.8(608)
--
-- https://tableplus.com/
--
-- Database: geo_app
-- Generation Time: 2025-06-09 18:03:43.5140
-- -------------------------------------------------------------


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


-- Tables préfixées "chat_"
CREATE TABLE chat_rooms (
  id VARCHAR(36) PRIMARY KEY,
  title VARCHAR(255),
  type ENUM('private', 'group', 'broadcast'),
  created_at TIMESTAMP,
  created_by INT
);

CREATE TABLE chat_messages (
  id VARCHAR(36) PRIMARY KEY,
  room_id VARCHAR(36),
  content TEXT,
  sender_id INT,
  sent_at TIMESTAMP,
  FOREIGN KEY (room_id) REFERENCES chat_rooms(id)
);

CREATE TABLE chat_participants (
  room_id VARCHAR(36),
  user_id INT,
  role INT,
  entite_id INT,
  joined_at TIMESTAMP,
  PRIMARY KEY (room_id, user_id)
);

CREATE TABLE chat_read_receipts (
  message_id VARCHAR(36),
  user_id INT,
  read_at TIMESTAMP,
  PRIMARY KEY (message_id, user_id)
);

CREATE TABLE `email_counter` (
  `id` int(10) unsigned NOT NULL DEFAULT 1,
  `hour_start` timestamp NULL DEFAULT NULL,
  `count` int(10) unsigned DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `email_queue` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_pass` int(10) unsigned NOT NULL DEFAULT 0,
  `to_email` varchar(255) DEFAULT NULL,
  `subject` varchar(255) DEFAULT NULL,
  `body` text DEFAULT NULL,
  `headers` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `status` enum('pending','sent','failed') DEFAULT 'pending',
  `attempts` int(10) unsigned DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `entites` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `encrypted_name` varchar(255) DEFAULT NULL,
  `adresse1` varchar(45) DEFAULT '',
  `adresse2` varchar(45) DEFAULT '',
  `code_postal` varchar(5) DEFAULT '',
  `ville` varchar(45) DEFAULT '',
  `fk_region` int(10) unsigned DEFAULT NULL,
  `fk_type` int(10) unsigned DEFAULT 1,
  `encrypted_phone` varchar(128) DEFAULT '',
  `encrypted_mobile` varchar(128) DEFAULT '',
  `encrypted_email` varchar(255) DEFAULT '',
  `gps_lat` varchar(20) NOT NULL DEFAULT '',
  `gps_lng` varchar(20) NOT NULL DEFAULT '',
  `chk_stripe` tinyint(1) unsigned DEFAULT 0,
  `encrypted_stripe_id` varchar(255) DEFAULT '',
  `encrypted_iban` varchar(255) DEFAULT '',
  `encrypted_bic` varchar(128) DEFAULT '',
  `chk_demo` tinyint(1) unsigned DEFAULT 1,
  `chk_mdp_manuel` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Gestion des mots de passe manuelle (1) ou automatique (0)',
  `chk_username_manuel` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Gestion des usernames manuelle (1) ou automatique (0)',
  `chk_copie_mail_recu` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `chk_accept_sms` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `entites_ibfk_1` (`fk_region`),
  KEY `entites_ibfk_2` (`fk_type`),
  CONSTRAINT `entites_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `entites_ibfk_2` FOREIGN KEY (`fk_type`) REFERENCES `x_entites_types` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1230 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `medias` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `support` varchar(45) NOT NULL DEFAULT '' COMMENT 'Type de support (entite, user, operation, passage)',
  `support_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'ID de élément associé',
  `fichier` varchar(250) NOT NULL DEFAULT '' COMMENT 'Nom du fichier stocké',
  `file_type` varchar(50) DEFAULT NULL COMMENT 'Extension du fichier (pdf, jpg, xlsx, etc.)',
  `file_category` varchar(50) DEFAULT NULL COMMENT 'export, logo, carte, etc.',
  `file_size` int(10) unsigned DEFAULT NULL COMMENT 'Taille du fichier en octets',
  `mime_type` varchar(100) DEFAULT NULL COMMENT 'Type MIME du fichier',
  `original_name` varchar(255) DEFAULT NULL COMMENT 'Nom original du fichier uploadé',
  `fk_entite` int(10) unsigned DEFAULT NULL COMMENT 'ID de entité propriétaire',
  `fk_operation` int(10) unsigned DEFAULT NULL COMMENT 'ID de opération (pour passages)',
  `file_path` varchar(500) DEFAULT NULL COMMENT 'Chemin complet du fichier',
  `original_width` int(10) unsigned DEFAULT NULL COMMENT 'Largeur originale de image',
  `original_height` int(10) unsigned DEFAULT NULL COMMENT 'Hauteur originale de image',
  `processed_width` int(10) unsigned DEFAULT NULL COMMENT 'Largeur après traitement',
  `processed_height` int(10) unsigned DEFAULT NULL COMMENT 'Hauteur après traitement',
  `is_processed` tinyint(1) unsigned DEFAULT 0 COMMENT 'Image redimensionnée (1) ou originale (0)',
  `description` varchar(100) NOT NULL DEFAULT '' COMMENT 'Description du fichier',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  `fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `idx_entite` (`fk_entite`),
  KEY `idx_operation` (`fk_operation`),
  KEY `idx_support_type` (`support`, `support_id`),
  KEY `idx_file_type` (`file_type`),
  KEY `idx_file_category` (`file_category`),
  CONSTRAINT `fk_medias_entite` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
  CONSTRAINT `fk_medias_operation` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE `ope_pass` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_sector` int(10) unsigned DEFAULT 0,
  `fk_user` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_adresse` varchar(25) DEFAULT '' COMMENT 'adresses.cp??.id',
  `passed_at` timestamp NULL DEFAULT NULL COMMENT 'Date du passage',
  `fk_type` int(10) unsigned DEFAULT 0,
  `numero` varchar(10) NOT NULL DEFAULT '',
  `rue` varchar(75) NOT NULL DEFAULT '',
  `rue_bis` varchar(1) NOT NULL DEFAULT '',
  `ville` varchar(75) NOT NULL DEFAULT '',
  `fk_habitat` int(10) unsigned DEFAULT 1,
  `appt` varchar(5) DEFAULT '',
  `niveau` varchar(5) DEFAULT '',
  `residence` varchar(75) DEFAULT '',
  `gps_lat` varchar(20) NOT NULL DEFAULT '',
  `gps_lng` varchar(20) NOT NULL DEFAULT '',
  `encrypted_name` varchar(255) NOT NULL DEFAULT '',
  `montant` decimal(7,2) NOT NULL DEFAULT 0.00,
  `fk_type_reglement` int(10) unsigned DEFAULT 1,
  `remarque` text DEFAULT '',
  `encrypted_email` varchar(255) DEFAULT '',
  `nom_recu` varchar(50) DEFAULT NULL,
  `date_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de réception',
  `date_creat_recu` timestamp NULL DEFAULT NULL COMMENT 'Date de création du reçu',
  `date_sent_recu` timestamp NULL DEFAULT NULL COMMENT 'Date envoi du reçu',
  `email_erreur` varchar(30) DEFAULT '',
  `chk_email_sent` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `encrypted_phone` varchar(128) NOT NULL DEFAULT '',
  `is_striped` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `docremis` tinyint(1) unsigned DEFAULT 0,
  `date_repasser` timestamp NULL DEFAULT NULL COMMENT 'Date prévue pour repasser',
  `nb_passages` int(11) DEFAULT 1 COMMENT 'Nb passages pour les a repasser',
  `chk_gps_maj` tinyint(1) unsigned DEFAULT 0,
  `chk_map_create` tinyint(1) unsigned DEFAULT 0,
  `chk_mobile` tinyint(1) unsigned DEFAULT 0,
  `chk_synchro` tinyint(1) unsigned DEFAULT 1 COMMENT 'chk synchro entre web et appli',
  `chk_api_adresse` tinyint(1) unsigned DEFAULT 0,
  `chk_maj_adresse` tinyint(1) unsigned DEFAULT 0,
  `anomalie` tinyint(1) unsigned DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned DEFAULT NULL,
  `chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_operation` (`fk_operation`),
  KEY `fk_sector` (`fk_sector`),
  KEY `fk_user` (`fk_user`),
  KEY `fk_type` (`fk_type`),
  KEY `fk_type_reglement` (`fk_type_reglement`),
  KEY `email` (`encrypted_email`),
  CONSTRAINT `ope_pass_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_pass_ibfk_2` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_pass_ibfk_3` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_pass_ibfk_4` FOREIGN KEY (`fk_type_reglement`) REFERENCES `x_types_reglements` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=19499566 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `ope_pass_histo` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_pass` int(10) unsigned NOT NULL DEFAULT 0,
  `date_histo` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date historique',
  `sujet` varchar(50) DEFAULT NULL,
  `remarque` varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `ope_pass_histo_fk_pass_IDX` (`fk_pass`) USING BTREE,
  KEY `ope_pass_histo_date_histo_IDX` (`date_histo`) USING BTREE,
  CONSTRAINT `ope_pass_histo_ibfk_1` FOREIGN KEY (`fk_pass`) REFERENCES `ope_pass` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6752 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `ope_sectors` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_old_sector` int(10) unsigned DEFAULT NULL,
  `libelle` varchar(75) NOT NULL DEFAULT '',
  `sector` text NOT NULL DEFAULT '',
  `color` varchar(7) NOT NULL DEFAULT '#4B77BE',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
  `chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`),
  KEY `fk_operation` (`fk_operation`),
  CONSTRAINT `ope_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=27675 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `ope_users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_user` int(10) unsigned NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned DEFAULT NULL,
  `chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `ope_users_ibfk_1` (`fk_operation`),
  KEY `ope_users_ibfk_2` (`fk_user`),
  CONSTRAINT `ope_users_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_users_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=199006 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `ope_users_sectors` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_operation` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_user` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_sector` int(10) unsigned NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`),
  KEY `fk_operation` (`fk_operation`),
  KEY `fk_user` (`fk_user`),
  KEY `fk_sector` (`fk_sector`),
  CONSTRAINT `ope_users_sectors_ibfk_1` FOREIGN KEY (`fk_operation`) REFERENCES `operations` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_users_sectors_ibfk_2` FOREIGN KEY (`fk_user`) REFERENCES `users` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `ope_users_sectors_ibfk_3` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=48082 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `operations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_entite` int(10) unsigned NOT NULL DEFAULT 1,
  `libelle` varchar(75) NOT NULL DEFAULT '',
  `date_deb` date NOT NULL DEFAULT '0000-00-00',
  `date_fin` date NOT NULL DEFAULT '0000-00-00',
  `chk_distinct_sectors` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned NOT NULL DEFAULT 0,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned NOT NULL DEFAULT 0,
  `chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_entite` (`fk_entite`),
  KEY `date_deb` (`date_deb`),
  CONSTRAINT `operations_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3121 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `params` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(35) NOT NULL DEFAULT '',
  `valeur` varchar(255) NOT NULL DEFAULT '',
  `aide` varchar(150) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `sectors_adresses` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_adresse` varchar(25) DEFAULT NULL COMMENT 'adresses.cp??.id',
  `osm_id` int(10) unsigned NOT NULL DEFAULT 0,
  `fk_sector` int(10) unsigned NOT NULL DEFAULT 0,
  `osm_name` varchar(50) NOT NULL DEFAULT '',
  `numero` varchar(5) NOT NULL DEFAULT '',
  `rue_bis` varchar(5) NOT NULL DEFAULT '',
  `rue` varchar(60) NOT NULL DEFAULT '',
  `cp` varchar(5) NOT NULL DEFAULT '',
  `ville` varchar(60) NOT NULL DEFAULT '',
  `gps_lat` varchar(20) NOT NULL DEFAULT '',
  `gps_lng` varchar(20) NOT NULL DEFAULT '',
  `osm_date_creat` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  PRIMARY KEY (`id`),
  KEY `sectors_adresses_fk_sector_index` (`fk_sector`),
  KEY `sectors_adresses_numero_index` (`numero`),
  KEY `sectors_adresses_rue_index` (`rue`),
  KEY `sectors_adresses_ville_index` (`ville`),
  CONSTRAINT `sectors_adresses_ibfk_1` FOREIGN KEY (`fk_sector`) REFERENCES `ope_sectors` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1562946 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_entite` int(10) unsigned DEFAULT 1,
  `fk_role` int(10) unsigned DEFAULT 1,
  `fk_titre` int(10) unsigned DEFAULT 1,
  `encrypted_name` varchar(255) DEFAULT NULL,
  `first_name` varchar(45) DEFAULT NULL,
  `sect_name` varchar(60) DEFAULT '',
  `encrypted_user_name` varchar(128) DEFAULT '',
  `user_pass_hash` varchar(60) DEFAULT NULL,
  `encrypted_phone` varchar(128) DEFAULT NULL,
  `encrypted_mobile` varchar(128) DEFAULT NULL,
  `encrypted_email` varchar(255) DEFAULT '',
  `chk_alert_email` tinyint(1) unsigned DEFAULT 1,
  `chk_suivi` tinyint(1) unsigned DEFAULT 0,
  `date_naissance` date DEFAULT NULL,
  `date_embauche` date DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Date de création',
  `fk_user_creat` int(10) unsigned DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'Date de modification',
  `fk_user_modif` int(10) unsigned DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `fk_entite` (`fk_entite`),
  KEY `username` (`encrypted_user_name`),
  KEY `users_ibfk_2` (`fk_role`),
  KEY `users_ibfk_3` (`fk_titre`),
  CONSTRAINT `users_ibfk_1` FOREIGN KEY (`fk_entite`) REFERENCES `entites` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `users_ibfk_2` FOREIGN KEY (`fk_role`) REFERENCES `x_users_roles` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `users_ibfk_3` FOREIGN KEY (`fk_titre`) REFERENCES `x_users_titres` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10027748 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_departements` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(3) DEFAULT NULL,
  `fk_region` int(10) unsigned DEFAULT 1,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `x_departements_ibfk_1` (`fk_region`),
  CONSTRAINT `x_departements_ibfk_1` FOREIGN KEY (`fk_region`) REFERENCES `x_regions` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_devises` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(3) DEFAULT NULL,
  `symbole` varchar(6) DEFAULT NULL,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_entites_types` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_pays` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(3) DEFAULT NULL,
  `fk_continent` int(10) unsigned DEFAULT NULL,
  `fk_devise` int(10) unsigned DEFAULT 1,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `x_pays_ibfk_1` (`fk_devise`),
  CONSTRAINT `x_pays_ibfk_1` FOREIGN KEY (`fk_devise`) REFERENCES `x_devises` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Table des pays avec leurs codes' `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_regions` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_pays` int(10) unsigned DEFAULT 1,
  `libelle` varchar(45) DEFAULT NULL,
  `libelle_long` varchar(45) DEFAULT NULL,
  `table_osm` varchar(45) DEFAULT NULL,
  `departements` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `x_regions_ibfk_1` (`fk_pays`),
  CONSTRAINT `x_regions_ibfk_1` FOREIGN KEY (`fk_pays`) REFERENCES `x_pays` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_types_passages` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(10) DEFAULT NULL,
  `color_button` varchar(15) DEFAULT NULL,
  `color_mark` varchar(15) DEFAULT NULL,
  `color_table` varchar(15) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_types_reglements` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_users_roles` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents rôles des utilisateurs' `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_users_titres` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `libelle` varchar(45) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Les différents titres des utilisateurs' `PAGE_COMPRESSED`='ON';

CREATE TABLE `x_villes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fk_departement` int(10) unsigned DEFAULT 1,
  `libelle` varchar(65) DEFAULT NULL,
  `code_postal` varchar(5) DEFAULT NULL,
  `code_insee` varchar(5) DEFAULT NULL,
  `chk_active` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `x_villes_ibfk_1` (`fk_departement`),
  CONSTRAINT `x_villes_ibfk_1` FOREIGN KEY (`fk_departement`) REFERENCES `x_departements` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=38950 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE TABLE `z_sessions` (
  `sid` text NOT NULL,
  `fk_user` int(11) NOT NULL,
  `role` varchar(10) DEFAULT NULL,
  `date_modified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `ip` varchar(50) NOT NULL,
  `browser` varchar(150) NOT NULL,
  `data` mediumtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `PAGE_COMPRESSED`='ON';

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `chat_conversations_unread` AS select `r`.`id` AS `id`,`r`.`type` AS `type`,`r`.`title` AS `title`,`r`.`date_creation` AS `date_creation`,`r`.`fk_user` AS `fk_user`,`r`.`fk_entite` AS `fk_entite`,`r`.`statut` AS `statut`,`r`.`description` AS `description`,`r`.`reply_permission` AS `reply_permission`,`r`.`is_pinned` AS `is_pinned`,`r`.`expiry_date` AS `expiry_date`,`r`.`updated_at` AS `updated_at`,count(distinct `m`.`id`) AS `total_messages`,count(distinct `rm`.`id`) AS `read_messages`,count(distinct `m`.`id`) - count(distinct `rm`.`id`) AS `unread_messages`,(select `geo_app`.`chat_messages`.`date_sent` from `chat_messages` where `geo_app`.`chat_messages`.`fk_room` = `r`.`id` order by `geo_app`.`chat_messages`.`date_sent` desc limit 1) AS `last_message_date` from ((`chat_rooms` `r` left join `chat_messages` `m` on(`r`.`id` = `m`.`fk_room`)) left join `chat_read_messages` `rm` on(`m`.`id` = `rm`.`fk_message`)) group by `r`.`id`;


/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;