-- ============================================================================
-- Polysco — structure (tables)
-- Base source : polysco-professionel-v2 (serveur 8.0.41) — généré le 2026-10-08 16:24:22
-- Compatible MySQL 8.0 et MariaDB >= 10.3 (testé sur 11.3). Encodage : utf8mb4.
-- ============================================================================
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS=0;
SET UNIQUE_CHECKS=0;
SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
SET time_zone='+00:00';

-- ATTENTION : chaque table est supprimée puis recréée (DROP TABLE IF EXISTS). À importer dans une base VIDE.

-- Table activation_tokens
DROP TABLE IF EXISTS `activation_tokens`;
CREATE TABLE `activation_tokens` (
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`email`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table cache
DROP TABLE IF EXISTS `cache`;
CREATE TABLE `cache` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` int NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_expiration_index` (`expiration`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table cache_locks
DROP TABLE IF EXISTS `cache_locks`;
CREATE TABLE `cache_locks` (
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `owner` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` int NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_locks_expiration_index` (`expiration`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table failed_jobs
DROP TABLE IF EXISTS `failed_jobs`;
CREATE TABLE `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table job_batches
DROP TABLE IF EXISTS `job_batches`;
CREATE TABLE `job_batches` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `total_jobs` int NOT NULL,
  `pending_jobs` int NOT NULL,
  `failed_jobs` int NOT NULL,
  `failed_job_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `options` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `cancelled_at` int DEFAULT NULL,
  `created_at` int NOT NULL,
  `finished_at` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table jobs
DROP TABLE IF EXISTS `jobs`;
CREATE TABLE `jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `queue` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `attempts` tinyint unsigned NOT NULL,
  `reserved_at` int unsigned DEFAULT NULL,
  `available_at` int unsigned NOT NULL,
  `created_at` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table migrations
DROP TABLE IF EXISTS `migrations`;
CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_absences
DROP TABLE IF EXISTS `n_absences`;
CREATE TABLE `n_absences` (
  `abs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `abs_seance_id` bigint unsigned NOT NULL,
  `abs_ins_id` bigint unsigned NOT NULL,
  `abs_type` enum('A','R') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `abs_duree_retard_min` smallint unsigned DEFAULT NULL,
  `abs_est_justifie` tinyint(1) NOT NULL DEFAULT '0',
  `abs_justif_statut` enum('aucun','en_attente','accepte','refuse') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'aucun',
  `abs_justif_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `abs_justif_motif_refus` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `abs_justif_depose_le` timestamp NULL DEFAULT NULL,
  `abs_justif_traite_par` bigint unsigned DEFAULT NULL,
  `abs_justif_traite_le` timestamp NULL DEFAULT NULL,
  `abs_justificatif_fichier_id` bigint unsigned DEFAULT NULL,
  `abs_modif_par_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `abs_seance_key` bigint unsigned GENERATED ALWAYS AS (if((`deleted_at` is null),`abs_seance_id`,NULL)) STORED,
  PRIMARY KEY (`abs_id`),
  UNIQUE KEY `uq_abs_seance_ins` (`abs_seance_key`,`abs_ins_id`),
  KEY `n_absences_abs_seance_id_foreign` (`abs_seance_id`),
  KEY `n_absences_abs_justificatif_fichier_id_foreign` (`abs_justificatif_fichier_id`),
  KEY `n_absences_abs_modif_par_user_id_foreign` (`abs_modif_par_user_id`),
  KEY `n_absences_abs_ins_id_abs_type_index` (`abs_ins_id`,`abs_type`),
  KEY `n_absences_created_by_foreign` (`created_by`),
  KEY `n_absences_updated_by_foreign` (`updated_by`),
  KEY `n_absences_abs_justif_traite_par_foreign` (`abs_justif_traite_par`),
  KEY `n_absences_abs_justif_statut_index` (`abs_justif_statut`),
  CONSTRAINT `n_absences_abs_ins_id_foreign` FOREIGN KEY (`abs_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_absences_abs_justif_traite_par_foreign` FOREIGN KEY (`abs_justif_traite_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_abs_justificatif_fichier_id_foreign` FOREIGN KEY (`abs_justificatif_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_abs_modif_par_user_id_foreign` FOREIGN KEY (`abs_modif_par_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_abs_seance_id_foreign` FOREIGN KEY (`abs_seance_id`) REFERENCES `n_seances` (`se_id`),
  CONSTRAINT `n_absences_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_abs_duree` CHECK (((`abs_duree_retard_min` is null) or (`abs_duree_retard_min` > 0))),
  CONSTRAINT `chk_abs_retard` CHECK (((`abs_type` = 'R') or (`abs_duree_retard_min` is null)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_absences_enseignants
DROP TABLE IF EXISTS `n_absences_enseignants`;
CREATE TABLE `n_absences_enseignants` (
  `abe_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `abe_prof_id` bigint unsigned NOT NULL,
  `abe_centre_id` bigint unsigned NOT NULL,
  `abe_date_debut` date NOT NULL,
  `abe_date_fin` date NOT NULL,
  `abe_heure_debut` time DEFAULT NULL,
  `abe_heure_fin` time DEFAULT NULL,
  `abe_motif` enum('maladie','conge','personnel','professionnel','formation','autre') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `abe_description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `abe_statut` enum('declaree','justifiee','non_justifiee','annulee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'declaree',
  `abe_justificatif_fichier_id` bigint unsigned DEFAULT NULL,
  `abe_commentaire_justification` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `abe_remplacant_prof_id` bigint unsigned DEFAULT NULL,
  `abe_rattrapage` enum('a_planifier','planifie','effectue','non_requis') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'a_planifier',
  `abe_date_rattrapage` date DEFAULT NULL,
  `abe_commentaire_rattrapage` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`abe_id`),
  KEY `n_absences_enseignants_abe_justificatif_fichier_id_foreign` (`abe_justificatif_fichier_id`),
  KEY `n_absences_enseignants_abe_remplacant_prof_id_foreign` (`abe_remplacant_prof_id`),
  KEY `n_absences_enseignants_created_by_foreign` (`created_by`),
  KEY `n_absences_enseignants_updated_by_foreign` (`updated_by`),
  KEY `n_absences_enseignants_abe_prof_id_abe_date_debut_index` (`abe_prof_id`,`abe_date_debut`),
  KEY `n_absences_enseignants_abe_centre_id_abe_date_debut_index` (`abe_centre_id`,`abe_date_debut`),
  CONSTRAINT `n_absences_enseignants_abe_centre_id_foreign` FOREIGN KEY (`abe_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_absences_enseignants_abe_justificatif_fichier_id_foreign` FOREIGN KEY (`abe_justificatif_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_enseignants_abe_prof_id_foreign` FOREIGN KEY (`abe_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_absences_enseignants_abe_remplacant_prof_id_foreign` FOREIGN KEY (`abe_remplacant_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_absences_enseignants_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_absences_enseignants_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_abe_dates` CHECK ((`abe_date_fin` >= `abe_date_debut`)),
  CONSTRAINT `chk_abe_heures` CHECK ((((`abe_heure_debut` is null) and (`abe_heure_fin` is null)) or ((`abe_heure_debut` is not null) and (`abe_heure_fin` is not null) and (`abe_heure_fin` > `abe_heure_debut`)))),
  CONSTRAINT `chk_abe_rattrapage` CHECK (((`abe_rattrapage` not in ('planifie','effectue')) or (`abe_date_rattrapage` is not null))),
  CONSTRAINT `chk_abe_remplacant` CHECK (((`abe_remplacant_prof_id` is null) or (`abe_remplacant_prof_id` <> `abe_prof_id`)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_admission_criteres
DROP TABLE IF EXISTS `n_admission_criteres`;
CREATE TABLE `n_admission_criteres` (
  `ac_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ac_adm_id` bigint unsigned NOT NULL,
  `ac_ca_id` bigint unsigned NOT NULL,
  `ac_sc_id` bigint unsigned NOT NULL,
  `ac_est_obligatoire` tinyint(1) NOT NULL DEFAULT '1',
  `ac_fichier_id` bigint unsigned DEFAULT NULL,
  `ac_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ac_valide_par` bigint unsigned DEFAULT NULL,
  `ac_valide_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ac_id`),
  UNIQUE KEY `n_admission_criteres_ac_adm_id_ac_ca_id_unique` (`ac_adm_id`,`ac_ca_id`),
  KEY `n_admission_criteres_ac_ca_id_foreign` (`ac_ca_id`),
  KEY `n_admission_criteres_ac_sc_id_foreign` (`ac_sc_id`),
  KEY `n_admission_criteres_ac_fichier_id_foreign` (`ac_fichier_id`),
  KEY `n_admission_criteres_ac_valide_par_foreign` (`ac_valide_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_admission_criteres_ac_adm_id_foreign` FOREIGN KEY (`ac_adm_id`) REFERENCES `n_admissions` (`adm_id`) ON DELETE CASCADE,
  CONSTRAINT `n_admission_criteres_ac_ca_id_foreign` FOREIGN KEY (`ac_ca_id`) REFERENCES `n_criteres_access` (`ca_id`),
  CONSTRAINT `n_admission_criteres_ac_fichier_id_foreign` FOREIGN KEY (`ac_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_admission_criteres_ac_sc_id_foreign` FOREIGN KEY (`ac_sc_id`) REFERENCES `n_statuts_criteres` (`sc_id`),
  CONSTRAINT `n_admission_criteres_ac_valide_par_foreign` FOREIGN KEY (`ac_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_admission_diplome
DROP TABLE IF EXISTS `n_admission_diplome`;
CREATE TABLE `n_admission_diplome` (
  `dip_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dip_adm_id` bigint unsigned NOT NULL,
  `dip_annee_id` bigint unsigned NOT NULL,
  `dip_numero` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `dip_mention_id` bigint unsigned DEFAULT NULL,
  `dip_releves_livres` tinyint(1) NOT NULL DEFAULT '0',
  `dip_livre` tinyint(1) NOT NULL DEFAULT '0',
  `dip_date` datetime DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dip_id`),
  KEY `n_admission_diplome_dip_adm_id_foreign` (`dip_adm_id`),
  KEY `n_admission_diplome_dip_annee_id_foreign` (`dip_annee_id`),
  KEY `n_admission_diplome_dip_mention_id_foreign` (`dip_mention_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_admission_diplome_dip_adm_id_foreign` FOREIGN KEY (`dip_adm_id`) REFERENCES `n_admissions` (`adm_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `n_admission_diplome_dip_annee_id_foreign` FOREIGN KEY (`dip_annee_id`) REFERENCES `n_annees_scolaires` (`as_id`) ON UPDATE CASCADE,
  CONSTRAINT `n_admission_diplome_dip_mention_id_foreign` FOREIGN KEY (`dip_mention_id`) REFERENCES `n_mentions` (`men_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_admissions
DROP TABLE IF EXISTS `n_admissions`;
CREATE TABLE `n_admissions` (
  `adm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `adm_seq` int unsigned NOT NULL,
  `adm_numero` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `adm_date` date NOT NULL,
  `adm_type` enum('M','S') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'M',
  `adm_etudiant_id` bigint unsigned NOT NULL,
  `adm_preins_id` bigint unsigned DEFAULT NULL,
  `adm_as_id` bigint unsigned NOT NULL,
  `adm_formation_id` bigint unsigned NOT NULL,
  `adm_centre_id` bigint unsigned NOT NULL,
  `adm_centre_admin_id` bigint unsigned NOT NULL,
  `adm_site_id` bigint unsigned DEFAULT NULL,
  `adm_statut_id` bigint unsigned NOT NULL,
  `adm_situation` enum('N','R','P') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_est_principale` tinyint(1) NOT NULL DEFAULT '1',
  `adm_est_centre_paiement` tinyint(1) NOT NULL DEFAULT '1',
  `adm_type_bac_id` bigint unsigned DEFAULT NULL,
  `adm_serie_bac_id` bigint unsigned DEFAULT NULL,
  `adm_bac_annee` smallint unsigned DEFAULT NULL,
  `adm_bac_mention_id` bigint unsigned DEFAULT NULL,
  `adm_bac_etablissement` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_bac_ville_id` bigint unsigned DEFAULT NULL,
  `adm_diplome_acces_type_id` bigint unsigned DEFAULT NULL,
  `adm_diplome_acces_specialite` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_premiere_annee_sup` smallint unsigned DEFAULT NULL,
  `adm_handicap` enum('N','A','M','V','AM','AV','MV','T','XX') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_est_resident` tinyint(1) DEFAULT NULL,
  `adm_est_fonctionnaire` tinyint(1) DEFAULT NULL,
  `adm_est_mobilite` tinyint(1) DEFAULT NULL,
  `adm_bourse_pourcentage` decimal(5,2) DEFAULT NULL,
  `adm_localite_id` bigint unsigned DEFAULT NULL,
  `adm_accord_peda` enum('V','O','R') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_commentaire_peda` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_accord_admin` enum('V','O','R') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_commentaire_admin` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `adm_mise_a_niveau` tinyint(1) NOT NULL DEFAULT '0',
  `adm_dossier_acceptation_fichier_id` bigint unsigned DEFAULT NULL,
  `adm_ref_externe` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `adm_principale_key` bigint unsigned GENERATED ALWAYS AS (if(((`adm_est_principale` = 1) and (`deleted_at` is null)),`adm_etudiant_id`,NULL)) STORED,
  `adm_centre_paiement_key` bigint unsigned GENERATED ALWAYS AS (if(((`adm_est_centre_paiement` = 1) and (`deleted_at` is null)),`adm_etudiant_id`,NULL)) STORED,
  PRIMARY KEY (`adm_id`),
  UNIQUE KEY `n_admissions_adm_numero_unique` (`adm_numero`),
  UNIQUE KEY `uq_adm_principale` (`adm_principale_key`),
  UNIQUE KEY `uq_adm_centre_paiement` (`adm_centre_paiement_key`),
  KEY `n_admissions_adm_etudiant_id_foreign` (`adm_etudiant_id`),
  KEY `n_admissions_adm_preins_id_foreign` (`adm_preins_id`),
  KEY `n_admissions_adm_as_id_foreign` (`adm_as_id`),
  KEY `n_admissions_adm_formation_id_foreign` (`adm_formation_id`),
  KEY `n_admissions_adm_centre_id_foreign` (`adm_centre_id`),
  KEY `n_admissions_adm_centre_admin_id_foreign` (`adm_centre_admin_id`),
  KEY `n_admissions_adm_statut_id_foreign` (`adm_statut_id`),
  KEY `n_admissions_adm_type_bac_id_foreign` (`adm_type_bac_id`),
  KEY `n_admissions_adm_serie_bac_id_foreign` (`adm_serie_bac_id`),
  KEY `n_admissions_adm_bac_mention_id_foreign` (`adm_bac_mention_id`),
  KEY `n_admissions_adm_bac_ville_id_foreign` (`adm_bac_ville_id`),
  KEY `n_admissions_adm_diplome_acces_type_id_foreign` (`adm_diplome_acces_type_id`),
  KEY `n_admissions_adm_localite_id_foreign` (`adm_localite_id`),
  KEY `n_admissions_adm_dossier_acceptation_fichier_id_foreign` (`adm_dossier_acceptation_fichier_id`),
  KEY `fk_adm_site_centre` (`adm_site_id`,`adm_centre_admin_id`),
  KEY `n_admissions_created_by_foreign` (`created_by`),
  KEY `n_admissions_updated_by_foreign` (`updated_by`),
  CONSTRAINT `fk_adm_site_centre` FOREIGN KEY (`adm_site_id`, `adm_centre_admin_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_admissions_adm_as_id_foreign` FOREIGN KEY (`adm_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_admissions_adm_bac_mention_id_foreign` FOREIGN KEY (`adm_bac_mention_id`) REFERENCES `n_mentions` (`men_id`),
  CONSTRAINT `n_admissions_adm_bac_ville_id_foreign` FOREIGN KEY (`adm_bac_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_admissions_adm_centre_admin_id_foreign` FOREIGN KEY (`adm_centre_admin_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_admissions_adm_centre_id_foreign` FOREIGN KEY (`adm_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_admissions_adm_diplome_acces_type_id_foreign` FOREIGN KEY (`adm_diplome_acces_type_id`) REFERENCES `n_types_diplomes_acces` (`tda_id`),
  CONSTRAINT `n_admissions_adm_dossier_acceptation_fichier_id_foreign` FOREIGN KEY (`adm_dossier_acceptation_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_admissions_adm_etudiant_id_foreign` FOREIGN KEY (`adm_etudiant_id`) REFERENCES `n_etudiants` (`etud_id`),
  CONSTRAINT `n_admissions_adm_formation_id_foreign` FOREIGN KEY (`adm_formation_id`) REFERENCES `n_formations` (`for_id`),
  CONSTRAINT `n_admissions_adm_localite_id_foreign` FOREIGN KEY (`adm_localite_id`) REFERENCES `n_localites` (`loc_id`),
  CONSTRAINT `n_admissions_adm_preins_id_foreign` FOREIGN KEY (`adm_preins_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE SET NULL,
  CONSTRAINT `n_admissions_adm_serie_bac_id_foreign` FOREIGN KEY (`adm_serie_bac_id`) REFERENCES `n_series_bac` (`sb_id`),
  CONSTRAINT `n_admissions_adm_statut_id_foreign` FOREIGN KEY (`adm_statut_id`) REFERENCES `n_statuts_admissions` (`sa_id`),
  CONSTRAINT `n_admissions_adm_type_bac_id_foreign` FOREIGN KEY (`adm_type_bac_id`) REFERENCES `n_types_bac` (`tb_id`),
  CONSTRAINT `n_admissions_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_admissions_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_adm_bac_annee` CHECK (((`adm_bac_annee` is null) or (`adm_bac_annee` between 1950 and 2100))),
  CONSTRAINT `chk_adm_bourse` CHECK (((`adm_bourse_pourcentage` is null) or (`adm_bourse_pourcentage` between 0 and 100)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_annees_scolaires
DROP TABLE IF EXISTS `n_annees_scolaires`;
CREATE TABLE `n_annees_scolaires` (
  `as_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `as_nom` char(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `as_annee_debut` smallint unsigned NOT NULL,
  `as_date_debut` date NOT NULL,
  `as_date_fin` date NOT NULL,
  `as_est_courante` tinyint(1) NOT NULL DEFAULT '0',
  `as_est_preinscription` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `as_courante_key` tinyint GENERATED ALWAYS AS (if((`as_est_courante` = 1),1,NULL)) STORED,
  `as_preinscription_key` tinyint GENERATED ALWAYS AS (if((`as_est_preinscription` = 1),1,NULL)) STORED,
  PRIMARY KEY (`as_id`),
  UNIQUE KEY `n_annees_scolaires_as_nom_unique` (`as_nom`),
  UNIQUE KEY `n_annees_scolaires_as_annee_debut_unique` (`as_annee_debut`),
  UNIQUE KEY `uq_as_courante` (`as_courante_key`),
  UNIQUE KEY `uq_as_preinscription` (`as_preinscription_key`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `chk_as_dates` CHECK ((`as_date_fin` > `as_date_debut`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_annonce_cibles
DROP TABLE IF EXISTS `n_annonce_cibles`;
CREATE TABLE `n_annonce_cibles` (
  `ac_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ac_ann_id` bigint unsigned NOT NULL,
  `ac_public` enum('etudiants','enseignants','personnel','parents') COLLATE utf8mb4_unicode_ci NOT NULL,
  `ac_centre_id` bigint unsigned DEFAULT NULL,
  `ac_formation_id` bigint unsigned DEFAULT NULL,
  `ac_filiere_id` bigint unsigned DEFAULT NULL,
  `ac_niveau` tinyint unsigned DEFAULT NULL,
  `ac_classe_id` bigint unsigned DEFAULT NULL,
  `ac_groupe_id` bigint unsigned DEFAULT NULL,
  `ac_mode_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ac_id`),
  KEY `n_annonce_cibles_ac_ann_id_foreign` (`ac_ann_id`),
  KEY `n_annonce_cibles_ac_centre_id_foreign` (`ac_centre_id`),
  KEY `n_annonce_cibles_ac_formation_id_foreign` (`ac_formation_id`),
  KEY `n_annonce_cibles_ac_filiere_id_foreign` (`ac_filiere_id`),
  KEY `n_annonce_cibles_ac_classe_id_foreign` (`ac_classe_id`),
  KEY `n_annonce_cibles_ac_groupe_id_foreign` (`ac_groupe_id`),
  KEY `n_annonce_cibles_ac_mode_id_foreign` (`ac_mode_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_annonce_cibles_ac_ann_id_foreign` FOREIGN KEY (`ac_ann_id`) REFERENCES `n_annonces` (`ann_id`) ON DELETE CASCADE,
  CONSTRAINT `n_annonce_cibles_ac_centre_id_foreign` FOREIGN KEY (`ac_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_annonce_cibles_ac_classe_id_foreign` FOREIGN KEY (`ac_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_annonce_cibles_ac_filiere_id_foreign` FOREIGN KEY (`ac_filiere_id`) REFERENCES `n_filieres` (`fil_id`),
  CONSTRAINT `n_annonce_cibles_ac_formation_id_foreign` FOREIGN KEY (`ac_formation_id`) REFERENCES `n_formations` (`for_id`),
  CONSTRAINT `n_annonce_cibles_ac_groupe_id_foreign` FOREIGN KEY (`ac_groupe_id`) REFERENCES `n_groupes` (`grp_id`),
  CONSTRAINT `n_annonce_cibles_ac_mode_id_foreign` FOREIGN KEY (`ac_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_annonce_destinataires
DROP TABLE IF EXISTS `n_annonce_destinataires`;
CREATE TABLE `n_annonce_destinataires` (
  `ad_ann_id` bigint unsigned NOT NULL,
  `ad_user_id` bigint unsigned NOT NULL,
  `ad_lue_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ad_ann_id`,`ad_user_id`),
  KEY `n_annonce_destinataires_ad_user_id_ad_lue_le_index` (`ad_user_id`,`ad_lue_le`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_annonce_destinataires_ad_ann_id_foreign` FOREIGN KEY (`ad_ann_id`) REFERENCES `n_annonces` (`ann_id`) ON DELETE CASCADE,
  CONSTRAINT `n_annonce_destinataires_ad_user_id_foreign` FOREIGN KEY (`ad_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_annonce_fichiers
DROP TABLE IF EXISTS `n_annonce_fichiers`;
CREATE TABLE `n_annonce_fichiers` (
  `af_ann_id` bigint unsigned NOT NULL,
  `af_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`af_ann_id`,`af_fichier_id`),
  KEY `n_annonce_fichiers_af_fichier_id_foreign` (`af_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_annonce_fichiers_af_ann_id_foreign` FOREIGN KEY (`af_ann_id`) REFERENCES `n_annonces` (`ann_id`) ON DELETE CASCADE,
  CONSTRAINT `n_annonce_fichiers_af_fichier_id_foreign` FOREIGN KEY (`af_fichier_id`) REFERENCES `n_fichiers` (`fic_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_annonces
DROP TABLE IF EXISTS `n_annonces`;
CREATE TABLE `n_annonces` (
  `ann_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ann_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ann_contenu` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `ann_categorie` enum('information','urgent','evenement','examen','vie_etudiante') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'information',
  `ann_statut` enum('brouillon','publiee','archivee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'brouillon',
  `ann_publier_le` timestamp NULL DEFAULT NULL,
  `ann_notifiee_le` timestamp NULL DEFAULT NULL,
  `ann_expire_le` timestamp NULL DEFAULT NULL,
  `ann_epinglee_jusqu_au` timestamp NULL DEFAULT NULL,
  `ann_evenement_debut` timestamp NULL DEFAULT NULL,
  `ann_evenement_fin` timestamp NULL DEFAULT NULL,
  `ann_lieu` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ann_lien` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ann_auteur_id` bigint unsigned NOT NULL,
  `ann_prof_id` bigint unsigned DEFAULT NULL,
  `ann_nb_destinataires` int unsigned NOT NULL DEFAULT '0',
  `ann_modifiee_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ann_id`),
  KEY `n_annonces_ann_auteur_id_foreign` (`ann_auteur_id`),
  KEY `n_annonces_ann_prof_id_foreign` (`ann_prof_id`),
  KEY `n_annonces_ann_statut_ann_publier_le_index` (`ann_statut`,`ann_publier_le`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_annonces_ann_auteur_id_foreign` FOREIGN KEY (`ann_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_annonces_ann_prof_id_foreign` FOREIGN KEY (`ann_prof_id`) REFERENCES `n_enseignants` (`prof_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_avancement_commentaires
DROP TABLE IF EXISTS `n_avancement_commentaires`;
CREATE TABLE `n_avancement_commentaires` (
  `avc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `avc_emo_id` bigint unsigned NOT NULL,
  `avc_groupe_id` bigint unsigned DEFAULT NULL,
  `avc_periode` enum('jour','soir') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `avc_seq_id` bigint unsigned DEFAULT NULL,
  `avc_commentaire` text COLLATE utf8mb4_unicode_ci,
  `avc_modifie_par` bigint unsigned DEFAULT NULL,
  `avc_groupe_key` bigint unsigned GENERATED ALWAYS AS (coalesce(`avc_groupe_id`,0)) STORED,
  `avc_periode_key` varchar(5) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS (coalesce(`avc_periode`,'')) STORED,
  `avc_seq_key` bigint unsigned GENERATED ALWAYS AS (coalesce(`avc_seq_id`,0)) STORED,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`avc_id`),
  UNIQUE KEY `uq_avc_contexte` (`avc_emo_id`,`avc_groupe_key`,`avc_periode_key`,`avc_seq_key`),
  KEY `n_avancement_commentaires_created_by_index` (`created_by`),
  CONSTRAINT `n_avancement_commentaires_avc_emo_id_foreign` FOREIGN KEY (`avc_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_avatars_defaut
DROP TABLE IF EXISTS `n_avatars_defaut`;
CREATE TABLE `n_avatars_defaut` (
  `avd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `avd_categorie` enum('etudiant','candidat','enseignant','personnel','tuteur') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `avd_sexe` enum('M','F','N') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `avd_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`avd_id`),
  UNIQUE KEY `n_avatars_defaut_avd_categorie_avd_sexe_unique` (`avd_categorie`,`avd_sexe`),
  KEY `n_avatars_defaut_avd_fichier_id_foreign` (`avd_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_avatars_defaut_avd_fichier_id_foreign` FOREIGN KEY (`avd_fichier_id`) REFERENCES `n_fichiers` (`fic_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_banques
DROP TABLE IF EXISTS `n_banques`;
CREATE TABLE `n_banques` (
  `bnk_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bnk_code` smallint unsigned NOT NULL,
  `bnk_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `bnk_nom_ar` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `bnk_description` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`bnk_id`),
  UNIQUE KEY `n_banques_bnk_code_unique` (`bnk_code`),
  UNIQUE KEY `n_banques_bnk_nom_unique` (`bnk_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_baremes_mentions
DROP TABLE IF EXISTS `n_baremes_mentions`;
CREATE TABLE `n_baremes_mentions` (
  `bm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bm_regle_id` bigint unsigned NOT NULL,
  `bm_portee` enum('semestre','annee','diplome') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'annee',
  `bm_note_min` decimal(5,2) NOT NULL,
  `bm_note_max` decimal(5,2) NOT NULL,
  `bm_mention` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `bm_decision` enum('admis','rattrapage','redoublement','exclusion') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `bm_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`bm_id`),
  UNIQUE KEY `uq_bareme` (`bm_regle_id`,`bm_portee`,`bm_note_min`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_baremes_mentions_bm_regle_id_foreign` FOREIGN KEY (`bm_regle_id`) REFERENCES `n_regles_evaluation` (`reg_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_bm_bornes` CHECK (((`bm_note_min` >= 0) and (`bm_note_max` <= 20) and (`bm_note_min` < `bm_note_max`)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_bordereaux_remise
DROP TABLE IF EXISTS `n_bordereaux_remise`;
CREATE TABLE `n_bordereaux_remise` (
  `bdr_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bdr_numero` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `bdr_date` date NOT NULL,
  `bdr_cs_id` bigint unsigned NOT NULL,
  `bdr_centre_id` bigint unsigned NOT NULL,
  `bdr_montant` decimal(12,2) NOT NULL,
  `bdr_nb_pieces` smallint unsigned NOT NULL,
  `bdr_commentaire` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `bdr_user_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`bdr_id`),
  UNIQUE KEY `n_bordereaux_remise_bdr_numero_unique` (`bdr_numero`),
  KEY `n_bordereaux_remise_bdr_cs_id_foreign` (`bdr_cs_id`),
  KEY `n_bordereaux_remise_bdr_user_id_foreign` (`bdr_user_id`),
  KEY `n_bordereaux_remise_bdr_centre_id_bdr_date_index` (`bdr_centre_id`,`bdr_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_bordereaux_remise_bdr_centre_id_foreign` FOREIGN KEY (`bdr_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_bordereaux_remise_bdr_cs_id_foreign` FOREIGN KEY (`bdr_cs_id`) REFERENCES `n_comptes_societe` (`cs_id`),
  CONSTRAINT `n_bordereaux_remise_bdr_user_id_foreign` FOREIGN KEY (`bdr_user_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `chk_bdr_montant` CHECK (((`bdr_montant` >= 0) and (`bdr_nb_pieces` > 0)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_budgets
DROP TABLE IF EXISTS `n_budgets`;
CREATE TABLE `n_budgets` (
  `bud_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `bud_libelle` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `bud_as_id` bigint unsigned NOT NULL,
  `bud_centre_id` bigint unsigned NOT NULL,
  `bud_est_definitif` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`bud_id`),
  UNIQUE KEY `n_budgets_bud_centre_id_bud_as_id_bud_libelle_unique` (`bud_centre_id`,`bud_as_id`,`bud_libelle`),
  KEY `n_budgets_bud_as_id_foreign` (`bud_as_id`),
  KEY `n_budgets_created_by_foreign` (`created_by`),
  KEY `n_budgets_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_budgets_bud_as_id_foreign` FOREIGN KEY (`bud_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_budgets_bud_centre_id_foreign` FOREIGN KEY (`bud_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_budgets_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_budgets_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_cahier_programme
DROP TABLE IF EXISTS `n_cahier_programme`;
CREATE TABLE `n_cahier_programme` (
  `cp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cp_cht_id` bigint unsigned NOT NULL,
  `cp_seq_id` bigint unsigned DEFAULT NULL,
  `cp_obj_id` bigint unsigned DEFAULT NULL,
  `cp_heures` decimal(5,2) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cp_id`),
  KEY `n_cahier_programme_cp_cht_id_foreign` (`cp_cht_id`),
  KEY `n_cahier_programme_cp_seq_id_foreign` (`cp_seq_id`),
  KEY `n_cahier_programme_cp_obj_id_foreign` (`cp_obj_id`),
  KEY `n_cahier_programme_created_by_index` (`created_by`),
  CONSTRAINT `n_cahier_programme_cp_cht_id_foreign` FOREIGN KEY (`cp_cht_id`) REFERENCES `n_cahier_text` (`cht_id`) ON DELETE CASCADE,
  CONSTRAINT `n_cahier_programme_cp_obj_id_foreign` FOREIGN KEY (`cp_obj_id`) REFERENCES `n_objectifs_programme` (`obj_id`) ON DELETE SET NULL,
  CONSTRAINT `n_cahier_programme_cp_seq_id_foreign` FOREIGN KEY (`cp_seq_id`) REFERENCES `n_sequences_pedagogiques` (`seq_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_cahier_text
DROP TABLE IF EXISTS `n_cahier_text`;
CREATE TABLE `n_cahier_text` (
  `cht_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cht_se_id` bigint unsigned NOT NULL,
  `cht_objectif` text COLLATE utf8mb4_unicode_ci,
  `cht_descriptif` text COLLATE utf8mb4_unicode_ci,
  `cht_observations` text COLLATE utf8mb4_unicode_ci,
  `cht_disposition` text COLLATE utf8mb4_unicode_ci,
  `cht_nbr_heures` decimal(5,2) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cht_id`),
  UNIQUE KEY `n_cahier_text_cht_se_id_unique` (`cht_se_id`),
  KEY `n_cahier_text_created_by_index` (`created_by`),
  CONSTRAINT `n_cahier_text_cht_se_id_foreign` FOREIGN KEY (`cht_se_id`) REFERENCES `n_seances` (`se_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_caisse
DROP TABLE IF EXISTS `n_caisse`;
CREATE TABLE `n_caisse` (
  `caisse_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `caisse_site_id` bigint unsigned NOT NULL,
  `caisse_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `caisse_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `caisse_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`caisse_id`),
  UNIQUE KEY `n_caisse_caisse_code_unique` (`caisse_code`),
  KEY `n_caisse_caisse_site_id_foreign` (`caisse_site_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_caisse_caisse_site_id_foreign` FOREIGN KEY (`caisse_site_id`) REFERENCES `n_sites` (`site_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_caissier
DROP TABLE IF EXISTS `n_caissier`;
CREATE TABLE `n_caissier` (
  `caissier_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `caissier_caisse_id` bigint unsigned NOT NULL,
  `caissier_user_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`caissier_id`),
  UNIQUE KEY `n_caissier_caissier_user_id_unique` (`caissier_user_id`),
  KEY `n_caissier_caissier_caisse_id_foreign` (`caissier_caisse_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_caissier_caissier_caisse_id_foreign` FOREIGN KEY (`caissier_caisse_id`) REFERENCES `n_caisse` (`caisse_id`) ON DELETE CASCADE,
  CONSTRAINT `n_caissier_caissier_user_id_foreign` FOREIGN KEY (`caissier_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_calendrier_historique
DROP TABLE IF EXISTS `n_calendrier_historique`;
CREATE TABLE `n_calendrier_historique` (
  `h_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `h_cal_id` bigint unsigned DEFAULT NULL,
  `h_as_id` bigint unsigned DEFAULT NULL,
  `h_centre_id` bigint unsigned DEFAULT NULL,
  `h_objet` enum('CALENDRIER','PERIODE','FERIE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `h_objet_id` bigint unsigned DEFAULT NULL,
  `h_action` enum('CREATION','MODIFICATION','SUPPRESSION','STATUT','DUPLICATION','GENERATION') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `h_resume` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `h_avant` json DEFAULT NULL,
  `h_apres` json DEFAULT NULL,
  `h_user_id` bigint unsigned DEFAULT NULL,
  `h_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`h_id`),
  KEY `n_calendrier_historique_h_centre_id_foreign` (`h_centre_id`),
  KEY `n_calendrier_historique_h_user_id_foreign` (`h_user_id`),
  KEY `n_calendrier_historique_h_cal_id_h_date_index` (`h_cal_id`,`h_date`),
  KEY `n_calendrier_historique_h_as_id_h_centre_id_h_date_index` (`h_as_id`,`h_centre_id`,`h_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_calendrier_historique_h_as_id_foreign` FOREIGN KEY (`h_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_calendrier_historique_h_cal_id_foreign` FOREIGN KEY (`h_cal_id`) REFERENCES `n_calendrier_pedagogiques` (`cal_id`) ON DELETE SET NULL,
  CONSTRAINT `n_calendrier_historique_h_centre_id_foreign` FOREIGN KEY (`h_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_calendrier_historique_h_user_id_foreign` FOREIGN KEY (`h_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_calendrier_pedagogiques
DROP TABLE IF EXISTS `n_calendrier_pedagogiques`;
CREATE TABLE `n_calendrier_pedagogiques` (
  `cal_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cal_as_id` bigint unsigned NOT NULL,
  `cal_centre_id` bigint unsigned NOT NULL,
  `cal_session_id` bigint unsigned NOT NULL,
  `cal_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cal_date_debut` date DEFAULT NULL,
  `cal_date_fin` date DEFAULT NULL,
  `cal_jours_ouvres` set('1','2','3','4','5','6','7') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '1,2,3,4,5,6',
  `cal_statut` enum('BROUILLON','VALIDE','ARCHIVE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'BROUILLON',
  `cal_source_id` bigint unsigned DEFAULT NULL,
  `cal_valide_par` bigint unsigned DEFAULT NULL,
  `cal_valide_le` timestamp NULL DEFAULT NULL,
  `cal_cree_par` bigint unsigned DEFAULT NULL,
  `cal_modifie_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cal_id`),
  UNIQUE KEY `uq_calendrier_pedagogiq_as_id_centre_sessio` (`cal_as_id`,`cal_centre_id`,`cal_session_id`),
  KEY `n_calendrier_pedagogiques_cal_centre_id_foreign` (`cal_centre_id`),
  KEY `n_calendrier_pedagogiques_cal_session_id_foreign` (`cal_session_id`),
  KEY `n_calendrier_pedagogiques_cal_source_id_foreign` (`cal_source_id`),
  KEY `n_calendrier_pedagogiques_cal_valide_par_foreign` (`cal_valide_par`),
  KEY `n_calendrier_pedagogiques_cal_cree_par_foreign` (`cal_cree_par`),
  KEY `n_calendrier_pedagogiques_cal_modifie_par_foreign` (`cal_modifie_par`),
  KEY `n_calendrier_pedagogiques_cal_statut_index` (`cal_statut`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_calendrier_pedagogiques_cal_as_id_foreign` FOREIGN KEY (`cal_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_calendrier_pedagogiques_cal_centre_id_foreign` FOREIGN KEY (`cal_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_calendrier_pedagogiques_cal_cree_par_foreign` FOREIGN KEY (`cal_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_calendrier_pedagogiques_cal_modifie_par_foreign` FOREIGN KEY (`cal_modifie_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_calendrier_pedagogiques_cal_session_id_foreign` FOREIGN KEY (`cal_session_id`) REFERENCES `n_session` (`sess_id`),
  CONSTRAINT `n_calendrier_pedagogiques_cal_source_id_foreign` FOREIGN KEY (`cal_source_id`) REFERENCES `n_calendrier_pedagogiques` (`cal_id`) ON DELETE SET NULL,
  CONSTRAINT `n_calendrier_pedagogiques_cal_valide_par_foreign` FOREIGN KEY (`cal_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_cal_dates` CHECK (((`cal_date_debut` is null) or (`cal_date_fin` is null) or (`cal_date_fin` >= `cal_date_debut`)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_calendrier_periode_niveaux
DROP TABLE IF EXISTS `n_calendrier_periode_niveaux`;
CREATE TABLE `n_calendrier_periode_niveaux` (
  `cpn_per_id` bigint unsigned NOT NULL,
  `cpn_niveau` tinyint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cpn_per_id`,`cpn_niveau`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_calendrier_periode_niveaux_cpn_per_id_foreign` FOREIGN KEY (`cpn_per_id`) REFERENCES `n_calendrier_periodes` (`per_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_cpn_niveau` CHECK ((`cpn_niveau` between 1 and 10))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_calendrier_periodes
DROP TABLE IF EXISTS `n_calendrier_periodes`;
CREATE TABLE `n_calendrier_periodes` (
  `per_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `per_cal_id` bigint unsigned NOT NULL,
  `per_type_id` bigint unsigned NOT NULL,
  `per_libelle` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `per_date_debut` date NOT NULL,
  `per_date_fin` date NOT NULL,
  `per_tous_niveaux` tinyint(1) NOT NULL DEFAULT '0',
  `per_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`per_id`),
  KEY `n_calendrier_periodes_per_type_id_foreign` (`per_type_id`),
  KEY `n_calendrier_periodes_created_by_foreign` (`created_by`),
  KEY `n_calendrier_periodes_updated_by_foreign` (`updated_by`),
  KEY `n_calendrier_periodes_per_cal_id_per_date_debut_index` (`per_cal_id`,`per_date_debut`),
  CONSTRAINT `n_calendrier_periodes_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_calendrier_periodes_per_cal_id_foreign` FOREIGN KEY (`per_cal_id`) REFERENCES `n_calendrier_pedagogiques` (`cal_id`) ON DELETE CASCADE,
  CONSTRAINT `n_calendrier_periodes_per_type_id_foreign` FOREIGN KEY (`per_type_id`) REFERENCES `n_types_details_calenders` (`dc_id`),
  CONSTRAINT `n_calendrier_periodes_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_per_dates` CHECK ((`per_date_fin` >= `per_date_debut`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_campagnes
DROP TABLE IF EXISTS `n_campagnes`;
CREATE TABLE `n_campagnes` (
  `camp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `camp_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `camp_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `camp_user_id` bigint unsigned DEFAULT NULL,
  `camp_canal_id` bigint unsigned DEFAULT NULL,
  `camp_centre_id` bigint unsigned NOT NULL,
  `camp_date_debut` date DEFAULT NULL,
  `camp_date_fin` date DEFAULT NULL,
  `camp_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`camp_id`),
  UNIQUE KEY `n_campagnes_camp_code_unique` (`camp_code`),
  KEY `n_campagnes_camp_user_id_foreign` (`camp_user_id`),
  KEY `n_campagnes_camp_canal_id_foreign` (`camp_canal_id`),
  KEY `n_campagnes_camp_centre_id_foreign` (`camp_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_campagnes_camp_canal_id_foreign` FOREIGN KEY (`camp_canal_id`) REFERENCES `n_canaux` (`canal_id`),
  CONSTRAINT `n_campagnes_camp_centre_id_foreign` FOREIGN KEY (`camp_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_campagnes_camp_user_id_foreign` FOREIGN KEY (`camp_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_camp_dates` CHECK (((`camp_date_fin` is null) or (`camp_date_debut` is null) or (`camp_date_fin` >= `camp_date_debut`)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_canaux
DROP TABLE IF EXISTS `n_canaux`;
CREATE TABLE `n_canaux` (
  `canal_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `canal_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `canal_icone` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `canal_demande_precision` tinyint(1) NOT NULL DEFAULT '0',
  `canal_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `canal_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `canal_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`canal_id`),
  UNIQUE KEY `n_canaux_canal_nom_unique` (`canal_nom`),
  UNIQUE KEY `n_canaux_canal_code_unique` (`canal_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_candidatures_stage
DROP TABLE IF EXISTS `n_candidatures_stage`;
CREATE TABLE `n_candidatures_stage` (
  `cs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cs_off_id` bigint unsigned NOT NULL,
  `cs_ins_id` bigint unsigned NOT NULL,
  `cs_message` text COLLATE utf8mb4_unicode_ci,
  `cs_cv_fichier_id` bigint unsigned DEFAULT NULL,
  `cs_statut` enum('envoyee','retenue','refusee','retiree') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'envoyee',
  `cs_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cs_traitee_par` bigint unsigned DEFAULT NULL,
  `cs_traitee_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cs_id`),
  UNIQUE KEY `n_candidatures_stage_cs_off_id_cs_ins_id_unique` (`cs_off_id`,`cs_ins_id`),
  KEY `n_candidatures_stage_cs_ins_id_foreign` (`cs_ins_id`),
  KEY `n_candidatures_stage_cs_cv_fichier_id_foreign` (`cs_cv_fichier_id`),
  KEY `n_candidatures_stage_cs_traitee_par_foreign` (`cs_traitee_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_candidatures_stage_cs_cv_fichier_id_foreign` FOREIGN KEY (`cs_cv_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_candidatures_stage_cs_ins_id_foreign` FOREIGN KEY (`cs_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_candidatures_stage_cs_off_id_foreign` FOREIGN KEY (`cs_off_id`) REFERENCES `n_offres_stage` (`off_id`) ON DELETE CASCADE,
  CONSTRAINT `n_candidatures_stage_cs_traitee_par_foreign` FOREIGN KEY (`cs_traitee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_centre_param
DROP TABLE IF EXISTS `n_centre_param`;
CREATE TABLE `n_centre_param` (
  `cp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cp_centre_id` bigint unsigned NOT NULL,
  `cp_centre_nom` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Nom officiel / juridique (documents) ; le nom affiché est n_centres.ct_nom',
  `cp_email` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_ville` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_province` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_address` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_siteweb` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_fix` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_tel` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_facebook` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_instagram` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_youtube` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_twitter` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_linkedin` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_logo_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'URL du logo du centre',
  `cp_recu_footer_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'URL de l''image de pied de reçu',
  `cp_documents_header_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'URL de l''en-tête des documents',
  `cp_logo_fichier_id` bigint unsigned DEFAULT NULL,
  `cp_recu_footer_fichier_id` bigint unsigned DEFAULT NULL,
  `cp_documents_header_fichier_id` bigint unsigned DEFAULT NULL,
  `cp_langue_principale` enum('FR','AR','EN') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'FR',
  `cp_couleur_principale` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_couleur_secondaire` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cp_police` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cp_id`),
  UNIQUE KEY `n_centre_param_cp_centre_id_unique` (`cp_centre_id`),
  KEY `n_centre_param_cp_logo_fichier_id_foreign` (`cp_logo_fichier_id`),
  KEY `n_centre_param_cp_recu_footer_fichier_id_foreign` (`cp_recu_footer_fichier_id`),
  KEY `n_centre_param_cp_documents_header_fichier_id_foreign` (`cp_documents_header_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_centre_param_cp_centre_id_foreign` FOREIGN KEY (`cp_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_centre_param_cp_documents_header_fichier_id_foreign` FOREIGN KEY (`cp_documents_header_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_centre_param_cp_logo_fichier_id_foreign` FOREIGN KEY (`cp_logo_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_centre_param_cp_recu_footer_fichier_id_foreign` FOREIGN KEY (`cp_recu_footer_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_centres
DROP TABLE IF EXISTS `n_centres`;
CREATE TABLE `n_centres` (
  `ct_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ct_etab_id` bigint unsigned DEFAULT NULL,
  `ct_code` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ct_nom` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ct_ville_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `ct_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ct_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ct_responsable` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ct_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ct_id`),
  UNIQUE KEY `n_centres_ct_code_unique` (`ct_code`),
  UNIQUE KEY `n_centres_ct_nom_unique` (`ct_nom`),
  KEY `n_centres_ct_ville_id_foreign` (`ct_ville_id`),
  KEY `n_centres_ct_etab_id_foreign` (`ct_etab_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_centres_ct_etab_id_foreign` FOREIGN KEY (`ct_etab_id`) REFERENCES `n_etablissements` (`etab_id`),
  CONSTRAINT `n_centres_ct_ville_id_foreign` FOREIGN KEY (`ct_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_changements_classe
DROP TABLE IF EXISTS `n_changements_classe`;
CREATE TABLE `n_changements_classe` (
  `chc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `chc_ins_id` bigint unsigned NOT NULL,
  `chc_type` enum('classe','groupe','specialite') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `chc_ancienne_classe_id` bigint unsigned DEFAULT NULL,
  `chc_nouvelle_classe_id` bigint unsigned DEFAULT NULL,
  `chc_ancien_groupe_id` bigint unsigned DEFAULT NULL,
  `chc_nouveau_groupe_id` bigint unsigned DEFAULT NULL,
  `chc_motif` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `chc_user_id` bigint unsigned DEFAULT NULL,
  `chc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`chc_id`),
  KEY `n_changements_classe_chc_ancienne_classe_id_foreign` (`chc_ancienne_classe_id`),
  KEY `n_changements_classe_chc_nouvelle_classe_id_foreign` (`chc_nouvelle_classe_id`),
  KEY `n_changements_classe_chc_ancien_groupe_id_foreign` (`chc_ancien_groupe_id`),
  KEY `n_changements_classe_chc_nouveau_groupe_id_foreign` (`chc_nouveau_groupe_id`),
  KEY `n_changements_classe_chc_user_id_foreign` (`chc_user_id`),
  KEY `n_changements_classe_chc_ins_id_chc_date_index` (`chc_ins_id`,`chc_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_changements_classe_chc_ancien_groupe_id_foreign` FOREIGN KEY (`chc_ancien_groupe_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_changements_classe_chc_ancienne_classe_id_foreign` FOREIGN KEY (`chc_ancienne_classe_id`) REFERENCES `n_classes` (`classe_id`) ON DELETE SET NULL,
  CONSTRAINT `n_changements_classe_chc_ins_id_foreign` FOREIGN KEY (`chc_ins_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE,
  CONSTRAINT `n_changements_classe_chc_nouveau_groupe_id_foreign` FOREIGN KEY (`chc_nouveau_groupe_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_changements_classe_chc_nouvelle_classe_id_foreign` FOREIGN KEY (`chc_nouvelle_classe_id`) REFERENCES `n_classes` (`classe_id`) ON DELETE SET NULL,
  CONSTRAINT `n_changements_classe_chc_user_id_foreign` FOREIGN KEY (`chc_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_classes
DROP TABLE IF EXISTS `n_classes`;
CREATE TABLE `n_classes` (
  `classe_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `classe_formation_id` bigint unsigned NOT NULL,
  `classe_centre_id` bigint unsigned NOT NULL,
  `classe_site_id` bigint unsigned DEFAULT NULL,
  `classe_abbr` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `classe_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `classe_nom_court` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `classe_nom_complet` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `classe_niveau_filiere` tinyint unsigned NOT NULL,
  `classe_niveau_apresbac` tinyint unsigned NOT NULL,
  `classe_as_debut_id` bigint unsigned NOT NULL,
  `classe_as_fin_id` bigint unsigned DEFAULT NULL,
  `classe_suivante_id` bigint unsigned DEFAULT NULL,
  `classe_est_visible` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `classe_capacite` smallint unsigned DEFAULT NULL,
  `classe_note_est_affichee` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`classe_id`),
  UNIQUE KEY `uq_classe` (`classe_formation_id`,`classe_niveau_filiere`,`classe_abbr`,`classe_as_debut_id`),
  KEY `n_classes_classe_centre_id_foreign` (`classe_centre_id`),
  KEY `n_classes_classe_as_debut_id_foreign` (`classe_as_debut_id`),
  KEY `n_classes_classe_as_fin_id_foreign` (`classe_as_fin_id`),
  KEY `n_classes_classe_suivante_id_foreign` (`classe_suivante_id`),
  KEY `fk_classe_site_centre` (`classe_site_id`,`classe_centre_id`),
  KEY `fk_classe_formation_centre` (`classe_formation_id`,`classe_centre_id`),
  KEY `n_classes_classe_formation_id_index` (`classe_formation_id`),
  KEY `n_classes_created_by_foreign` (`created_by`),
  KEY `n_classes_updated_by_foreign` (`updated_by`),
  CONSTRAINT `fk_classe_formation_centre` FOREIGN KEY (`classe_formation_id`, `classe_centre_id`) REFERENCES `n_formations` (`for_id`, `for_centre_id`),
  CONSTRAINT `fk_classe_site_centre` FOREIGN KEY (`classe_site_id`, `classe_centre_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_classes_classe_as_debut_id_foreign` FOREIGN KEY (`classe_as_debut_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_classes_classe_as_fin_id_foreign` FOREIGN KEY (`classe_as_fin_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_classes_classe_centre_id_foreign` FOREIGN KEY (`classe_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_classes_classe_suivante_id_foreign` FOREIGN KEY (`classe_suivante_id`) REFERENCES `n_classes` (`classe_id`) ON DELETE SET NULL,
  CONSTRAINT `n_classes_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_classes_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_clotures_caisse
DROP TABLE IF EXISTS `n_clotures_caisse`;
CREATE TABLE `n_clotures_caisse` (
  `clc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `clc_caisse_id` bigint unsigned NOT NULL,
  `clc_date` date NOT NULL,
  `clc_nb_recus` int unsigned NOT NULL,
  `clc_total` decimal(12,2) NOT NULL,
  `clc_especes_theoriques` decimal(12,2) NOT NULL,
  `clc_especes_comptees` decimal(12,2) NOT NULL,
  `clc_ecart` decimal(12,2) NOT NULL,
  `clc_totaux_modes` json NOT NULL,
  `clc_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `clc_user_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`clc_id`),
  UNIQUE KEY `n_clotures_caisse_clc_caisse_id_clc_date_unique` (`clc_caisse_id`,`clc_date`),
  KEY `n_clotures_caisse_clc_user_id_foreign` (`clc_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_clotures_caisse_clc_caisse_id_foreign` FOREIGN KEY (`clc_caisse_id`) REFERENCES `n_caisse` (`caisse_id`),
  CONSTRAINT `n_clotures_caisse_clc_user_id_foreign` FOREIGN KEY (`clc_user_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `chk_clc_montants` CHECK (((`clc_total` >= 0) and (`clc_especes_theoriques` >= 0) and (`clc_especes_comptees` >= 0)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_competences
DROP TABLE IF EXISTS `n_competences`;
CREATE TABLE `n_competences` (
  `comp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `comp_uf_id` bigint unsigned NOT NULL,
  `comp_libelle` varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL,
  `comp_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`comp_id`),
  KEY `n_competences_comp_uf_id_foreign` (`comp_uf_id`),
  KEY `n_competences_created_by_index` (`created_by`),
  CONSTRAINT `n_competences_comp_uf_id_foreign` FOREIGN KEY (`comp_uf_id`) REFERENCES `n_unites_formation` (`uf_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_comptes_societe
DROP TABLE IF EXISTS `n_comptes_societe`;
CREATE TABLE `n_comptes_societe` (
  `cs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cs_numero` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cs_rib` char(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cs_agence` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cs_banque_id` bigint unsigned NOT NULL,
  `cs_ville_id` bigint unsigned DEFAULT NULL,
  `cs_centre_id` bigint unsigned NOT NULL,
  `cs_est_principal` tinyint(1) NOT NULL DEFAULT '0',
  `cs_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `cs_principal_key` bigint unsigned GENERATED ALWAYS AS (if((`cs_est_principal` = 1),`cs_centre_id`,NULL)) STORED,
  PRIMARY KEY (`cs_id`),
  UNIQUE KEY `n_comptes_societe_cs_rib_unique` (`cs_rib`),
  UNIQUE KEY `uq_cs_principal` (`cs_principal_key`),
  KEY `n_comptes_societe_cs_banque_id_foreign` (`cs_banque_id`),
  KEY `n_comptes_societe_cs_ville_id_foreign` (`cs_ville_id`),
  KEY `n_comptes_societe_cs_centre_id_foreign` (`cs_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_comptes_societe_cs_banque_id_foreign` FOREIGN KEY (`cs_banque_id`) REFERENCES `n_banques` (`bnk_id`),
  CONSTRAINT `n_comptes_societe_cs_centre_id_foreign` FOREIGN KEY (`cs_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_comptes_societe_cs_ville_id_foreign` FOREIGN KEY (`cs_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_consentements
DROP TABLE IF EXISTS `n_consentements`;
CREATE TABLE `n_consentements` (
  `cons_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cons_user_id` bigint unsigned NOT NULL,
  `cons_type` enum('cgu','donnees_personnelles','communication_commerciale','droit_image','reglement_interieur') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cons_version` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cons_est_accorde` tinyint(1) NOT NULL,
  `cons_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cons_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cons_id`),
  KEY `n_consentements_cons_user_id_cons_type_cons_date_index` (`cons_user_id`,`cons_type`,`cons_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_consentements_cons_user_id_foreign` FOREIGN KEY (`cons_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_conversation_participants
DROP TABLE IF EXISTS `n_conversation_participants`;
CREATE TABLE `n_conversation_participants` (
  `cp_conv_id` bigint unsigned NOT NULL,
  `cp_user_id` bigint unsigned NOT NULL,
  `cp_lu_le` timestamp NULL DEFAULT NULL,
  `cp_archivee` tinyint(1) NOT NULL DEFAULT '0',
  `cp_sourdine` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cp_conv_id`,`cp_user_id`),
  KEY `n_conversation_participants_cp_user_id_index` (`cp_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_conversation_participants_cp_conv_id_foreign` FOREIGN KEY (`cp_conv_id`) REFERENCES `n_conversations` (`conv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_conversation_participants_cp_user_id_foreign` FOREIGN KEY (`cp_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_conversations
DROP TABLE IF EXISTS `n_conversations`;
CREATE TABLE `n_conversations` (
  `conv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `conv_type` enum('privee','groupe','service') COLLATE utf8mb4_unicode_ci NOT NULL,
  `conv_sujet` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `conv_service` enum('scolarite','finance','pedagogie') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `conv_centre_id` bigint unsigned DEFAULT NULL,
  `conv_service_lu_le` timestamp NULL DEFAULT NULL,
  `conv_cree_par` bigint unsigned NOT NULL,
  `conv_dernier_message_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`conv_id`),
  KEY `n_conversations_conv_centre_id_foreign` (`conv_centre_id`),
  KEY `n_conversations_conv_cree_par_foreign` (`conv_cree_par`),
  KEY `idx_conv_service` (`conv_service`,`conv_centre_id`,`conv_dernier_message_le`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_conversations_conv_centre_id_foreign` FOREIGN KEY (`conv_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_conversations_conv_cree_par_foreign` FOREIGN KEY (`conv_cree_par`) REFERENCES `n_utilisateurs` (`user_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_credit_modules
DROP TABLE IF EXISTS `n_credit_modules`;
CREATE TABLE `n_credit_modules` (
  `cm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cm_module_id` bigint unsigned NOT NULL,
  `cm_sem_id` bigint unsigned NOT NULL,
  `cm_classe_id` bigint unsigned NOT NULL,
  `cm_credit` tinyint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cm_id`),
  UNIQUE KEY `uq_cm_module_sem_classe` (`cm_module_id`,`cm_sem_id`,`cm_classe_id`),
  KEY `n_credit_modules_cm_sem_id_foreign` (`cm_sem_id`),
  KEY `n_credit_modules_cm_classe_id_foreign` (`cm_classe_id`),
  KEY `n_credit_modules_created_by_foreign` (`created_by`),
  KEY `n_credit_modules_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_credit_modules_cm_classe_id_foreign` FOREIGN KEY (`cm_classe_id`) REFERENCES `n_classes` (`classe_id`) ON DELETE CASCADE,
  CONSTRAINT `n_credit_modules_cm_module_id_foreign` FOREIGN KEY (`cm_module_id`) REFERENCES `n_modules` (`mod_id`) ON DELETE CASCADE,
  CONSTRAINT `n_credit_modules_cm_sem_id_foreign` FOREIGN KEY (`cm_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `n_credit_modules_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_credit_modules_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_cm_credit` CHECK ((`cm_credit` <= 60))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_creneaux_horaires
DROP TABLE IF EXISTS `n_creneaux_horaires`;
CREATE TABLE `n_creneaux_horaires` (
  `cr_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cr_centre_id` bigint unsigned DEFAULT NULL,
  `cr_libelle` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cr_heure_debut` time NOT NULL,
  `cr_heure_fin` time NOT NULL,
  `cr_type` enum('cours','pause') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'cours',
  `cr_modalite` enum('presentiel','distanciel') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'presentiel',
  `cr_jours` set('1','2','3','4','5','6','7') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '1,2,3,4,5,6',
  `cr_est_ramadan` tinyint(1) NOT NULL DEFAULT '0',
  `cr_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `cr_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cr_id`),
  KEY `n_creneaux_horaires_cr_centre_id_foreign` (`cr_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_creneaux_horaires_cr_centre_id_foreign` FOREIGN KEY (`cr_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_cr_heures` CHECK ((`cr_heure_fin` > `cr_heure_debut`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_criteres_access
DROP TABLE IF EXISTS `n_criteres_access`;
CREATE TABLE `n_criteres_access` (
  `ca_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ca_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ca_nom` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ca_libelle` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ca_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `ca_est_visible_etudiant` tinyint(1) NOT NULL DEFAULT '1',
  `ca_est_imprime` tinyint(1) NOT NULL DEFAULT '1',
  `ca_est_obligatoire` tinyint(1) NOT NULL DEFAULT '0',
  `ca_niv_min` tinyint unsigned NOT NULL DEFAULT '0',
  `ca_niv_max` tinyint unsigned NOT NULL DEFAULT '0',
  `ca_portee` enum('T','E','M') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ca_id`),
  UNIQUE KEY `n_criteres_access_ca_code_unique` (`ca_code`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `chk_ca_niveaux` CHECK ((`ca_niv_min` <= `ca_niv_max`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_deliberations
DROP TABLE IF EXISTS `n_deliberations`;
CREATE TABLE `n_deliberations` (
  `del_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `del_status` enum('P','F','C') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'P',
  `del_classe_id` bigint unsigned NOT NULL,
  `del_as_id` bigint unsigned NOT NULL,
  `del_sem_id` bigint unsigned NOT NULL,
  `del_date_prevue` datetime DEFAULT NULL,
  `del_date_effectuee` timestamp NULL DEFAULT NULL,
  `del_confirmee_le` timestamp NULL DEFAULT NULL,
  `del_confirmee_par` bigint unsigned DEFAULT NULL,
  `del_motif_reouverture` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `del_publiee_le` timestamp NULL DEFAULT NULL,
  `del_publiee_par` bigint unsigned DEFAULT NULL,
  `del_commentaire` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `del_fichier_id` bigint unsigned DEFAULT NULL,
  `del_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`del_id`),
  UNIQUE KEY `uq_del_classe_as_sem` (`del_classe_id`,`del_as_id`,`del_sem_id`),
  KEY `n_deliberations_del_as_id_foreign` (`del_as_id`),
  KEY `n_deliberations_del_sem_id_foreign` (`del_sem_id`),
  KEY `n_deliberations_del_fichier_id_foreign` (`del_fichier_id`),
  KEY `n_deliberations_created_by_foreign` (`created_by`),
  KEY `n_deliberations_updated_by_foreign` (`updated_by`),
  KEY `n_deliberations_del_confirmee_par_foreign` (`del_confirmee_par`),
  KEY `n_deliberations_del_publiee_par_foreign` (`del_publiee_par`),
  CONSTRAINT `n_deliberations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_deliberations_del_as_id_foreign` FOREIGN KEY (`del_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_deliberations_del_classe_id_foreign` FOREIGN KEY (`del_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_deliberations_del_confirmee_par_foreign` FOREIGN KEY (`del_confirmee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_deliberations_del_fichier_id_foreign` FOREIGN KEY (`del_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_deliberations_del_publiee_par_foreign` FOREIGN KEY (`del_publiee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_deliberations_del_sem_id_foreign` FOREIGN KEY (`del_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `n_deliberations_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_demande_commentaires
DROP TABLE IF EXISTS `n_demande_commentaires`;
CREATE TABLE `n_demande_commentaires` (
  `cd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cd_demande_id` bigint unsigned NOT NULL,
  `cd_user_id` bigint unsigned DEFAULT NULL,
  `cd_commentaire` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cd_est_public` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cd_id`),
  KEY `n_demande_commentaires_cd_demande_id_foreign` (`cd_demande_id`),
  KEY `n_demande_commentaires_cd_user_id_foreign` (`cd_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_demande_commentaires_cd_demande_id_foreign` FOREIGN KEY (`cd_demande_id`) REFERENCES `n_demandes` (`dem_id`) ON DELETE CASCADE,
  CONSTRAINT `n_demande_commentaires_cd_user_id_foreign` FOREIGN KEY (`cd_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_demandes
DROP TABLE IF EXISTS `n_demandes`;
CREATE TABLE `n_demandes` (
  `dem_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dem_statut_id` bigint unsigned NOT NULL,
  `dem_ins_id` bigint unsigned NOT NULL,
  `dem_type_id` bigint unsigned NOT NULL,
  `dem_typedoc_id` bigint unsigned DEFAULT NULL,
  `dem_type_recl_id` bigint unsigned DEFAULT NULL,
  `dem_modele_id` bigint unsigned DEFAULT NULL,
  `dem_site_id` bigint unsigned DEFAULT NULL,
  `dem_format` enum('S','P') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dem_objet` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dem_details` varchar(800) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dem_contenu` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `dem_preuve_fichier_id` bigint unsigned DEFAULT NULL,
  `dem_ticket_glpi_id` bigint unsigned DEFAULT NULL,
  `dem_date_souhaitee` date DEFAULT NULL,
  `dem_date_prevision` date DEFAULT NULL,
  `dem_date_prise_en_compte` timestamp NULL DEFAULT NULL,
  `dem_date_dispo` timestamp NULL DEFAULT NULL,
  `dem_date_livraison` timestamp NULL DEFAULT NULL,
  `dem_createur_id` bigint unsigned DEFAULT NULL,
  `dem_user_id` bigint unsigned DEFAULT NULL,
  `dem_prete_par` bigint unsigned DEFAULT NULL,
  `dem_livre_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dem_id`),
  UNIQUE KEY `n_demandes_dem_ticket_glpi_id_unique` (`dem_ticket_glpi_id`),
  KEY `n_demandes_dem_ins_id_foreign` (`dem_ins_id`),
  KEY `n_demandes_dem_type_id_foreign` (`dem_type_id`),
  KEY `n_demandes_dem_typedoc_id_foreign` (`dem_typedoc_id`),
  KEY `n_demandes_dem_type_recl_id_foreign` (`dem_type_recl_id`),
  KEY `n_demandes_dem_modele_id_foreign` (`dem_modele_id`),
  KEY `n_demandes_dem_site_id_foreign` (`dem_site_id`),
  KEY `n_demandes_dem_preuve_fichier_id_foreign` (`dem_preuve_fichier_id`),
  KEY `n_demandes_dem_createur_id_foreign` (`dem_createur_id`),
  KEY `n_demandes_dem_user_id_foreign` (`dem_user_id`),
  KEY `n_demandes_dem_prete_par_foreign` (`dem_prete_par`),
  KEY `n_demandes_dem_livre_par_foreign` (`dem_livre_par`),
  KEY `n_demandes_dem_statut_id_created_at_index` (`dem_statut_id`,`created_at`),
  KEY `n_demandes_created_by_foreign` (`created_by`),
  KEY `n_demandes_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_demandes_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_dem_createur_id_foreign` FOREIGN KEY (`dem_createur_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_dem_ins_id_foreign` FOREIGN KEY (`dem_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_demandes_dem_livre_par_foreign` FOREIGN KEY (`dem_livre_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_dem_modele_id_foreign` FOREIGN KEY (`dem_modele_id`) REFERENCES `n_modeles_documents` (`mdoc_id`),
  CONSTRAINT `n_demandes_dem_prete_par_foreign` FOREIGN KEY (`dem_prete_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_dem_preuve_fichier_id_foreign` FOREIGN KEY (`dem_preuve_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_dem_site_id_foreign` FOREIGN KEY (`dem_site_id`) REFERENCES `n_sites` (`site_id`),
  CONSTRAINT `n_demandes_dem_statut_id_foreign` FOREIGN KEY (`dem_statut_id`) REFERENCES `n_statuts_demandes` (`ds_id`),
  CONSTRAINT `n_demandes_dem_type_id_foreign` FOREIGN KEY (`dem_type_id`) REFERENCES `n_types_demandes` (`tdem_id`),
  CONSTRAINT `n_demandes_dem_type_recl_id_foreign` FOREIGN KEY (`dem_type_recl_id`) REFERENCES `n_types_reclamation` (`trec_id`),
  CONSTRAINT `n_demandes_dem_typedoc_id_foreign` FOREIGN KEY (`dem_typedoc_id`) REFERENCES `n_types_documents` (`tdoc_id`),
  CONSTRAINT `n_demandes_dem_user_id_foreign` FOREIGN KEY (`dem_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_demandes_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_dem_dates` CHECK (((`dem_date_livraison` is null) or (`dem_date_dispo` is null) or (`dem_date_livraison` >= `dem_date_dispo`))),
  CONSTRAINT `chk_dem_doc_ou_recl` CHECK (((`dem_typedoc_id` is null) or (`dem_type_recl_id` is null)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_devoir_delais
DROP TABLE IF EXISTS `n_devoir_delais`;
CREATE TABLE `n_devoir_delais` (
  `dd_dev_id` bigint unsigned NOT NULL,
  `dd_ins_id` bigint unsigned NOT NULL,
  `dd_limite` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dd_dev_id`,`dd_ins_id`),
  KEY `n_devoir_delais_dd_ins_id_foreign` (`dd_ins_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_devoir_delais_dd_dev_id_foreign` FOREIGN KEY (`dd_dev_id`) REFERENCES `n_devoirs` (`dev_id`) ON DELETE CASCADE,
  CONSTRAINT `n_devoir_delais_dd_ins_id_foreign` FOREIGN KEY (`dd_ins_id`) REFERENCES `n_inscriptions` (`ins_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_devoir_fichiers
DROP TABLE IF EXISTS `n_devoir_fichiers`;
CREATE TABLE `n_devoir_fichiers` (
  `df_dev_id` bigint unsigned NOT NULL,
  `df_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`df_dev_id`,`df_fichier_id`),
  KEY `n_devoir_fichiers_df_fichier_id_foreign` (`df_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_devoir_fichiers_df_dev_id_foreign` FOREIGN KEY (`df_dev_id`) REFERENCES `n_devoirs` (`dev_id`) ON DELETE CASCADE,
  CONSTRAINT `n_devoir_fichiers_df_fichier_id_foreign` FOREIGN KEY (`df_fichier_id`) REFERENCES `n_fichiers` (`fic_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_devoirs
DROP TABLE IF EXISTS `n_devoirs`;
CREATE TABLE `n_devoirs` (
  `dev_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dev_emo_id` bigint unsigned NOT NULL,
  `dev_as_id` bigint unsigned NOT NULL,
  `dev_groupe_id` bigint unsigned DEFAULT NULL,
  `dev_mode_id` bigint unsigned DEFAULT NULL,
  `dev_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `dev_consignes` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `dev_ouverture` timestamp NULL DEFAULT NULL,
  `dev_limite` timestamp NOT NULL,
  `dev_retard_accepte` tinyint(1) NOT NULL DEFAULT '0',
  `dev_est_note` tinyint(1) NOT NULL DEFAULT '1',
  `dev_exam_id` bigint unsigned DEFAULT NULL,
  `dev_statut` enum('brouillon','publie','archive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'brouillon',
  `dev_notifie_le` timestamp NULL DEFAULT NULL,
  `dev_rappel_le` timestamp NULL DEFAULT NULL,
  `dev_auteur_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dev_id`),
  KEY `n_devoirs_dev_as_id_foreign` (`dev_as_id`),
  KEY `n_devoirs_dev_groupe_id_foreign` (`dev_groupe_id`),
  KEY `n_devoirs_dev_mode_id_foreign` (`dev_mode_id`),
  KEY `n_devoirs_dev_exam_id_foreign` (`dev_exam_id`),
  KEY `n_devoirs_dev_auteur_id_foreign` (`dev_auteur_id`),
  KEY `n_devoirs_dev_emo_id_dev_as_id_index` (`dev_emo_id`,`dev_as_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_devoirs_dev_as_id_foreign` FOREIGN KEY (`dev_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_devoirs_dev_auteur_id_foreign` FOREIGN KEY (`dev_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_devoirs_dev_emo_id_foreign` FOREIGN KEY (`dev_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_devoirs_dev_exam_id_foreign` FOREIGN KEY (`dev_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE SET NULL,
  CONSTRAINT `n_devoirs_dev_groupe_id_foreign` FOREIGN KEY (`dev_groupe_id`) REFERENCES `n_groupes` (`grp_id`),
  CONSTRAINT `n_devoirs_dev_mode_id_foreign` FOREIGN KEY (`dev_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_diplomes
DROP TABLE IF EXISTS `n_diplomes`;
CREATE TABLE `n_diplomes` (
  `dip_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dip_abbr` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dip_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dip_nb_annees` tinyint unsigned NOT NULL,
  `dip_niveau_apresbac` tinyint unsigned NOT NULL,
  `dip_gd_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `dip_approche` enum('competences','objectifs','lmd') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dip_id`),
  UNIQUE KEY `n_diplomes_dip_abbr_unique` (`dip_abbr`),
  KEY `n_diplomes_dip_gd_id_foreign` (`dip_gd_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_diplomes_dip_gd_id_foreign` FOREIGN KEY (`dip_gd_id`) REFERENCES `n_groupement_diplomes` (`gd_id`),
  CONSTRAINT `chk_dip_nb_annees` CHECK ((`dip_nb_annees` between 1 and 8))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_diplomes_acces
DROP TABLE IF EXISTS `n_diplomes_acces`;
CREATE TABLE `n_diplomes_acces` (
  `da_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `da_preins_id` bigint unsigned NOT NULL,
  `da_type_diplome_id` bigint unsigned DEFAULT NULL,
  `da_specialite` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `da_mention_id` bigint unsigned DEFAULT NULL,
  `da_etablissement` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `da_type_etablissement` enum('public','prive') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `da_pays_id` bigint unsigned DEFAULT NULL,
  `da_ville_id` bigint unsigned DEFAULT NULL,
  `da_annee` smallint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`da_id`),
  UNIQUE KEY `n_diplomes_acces_da_preins_id_unique` (`da_preins_id`),
  KEY `n_diplomes_acces_da_type_diplome_id_foreign` (`da_type_diplome_id`),
  KEY `n_diplomes_acces_da_mention_id_foreign` (`da_mention_id`),
  KEY `n_diplomes_acces_da_pays_id_foreign` (`da_pays_id`),
  KEY `n_diplomes_acces_da_ville_id_foreign` (`da_ville_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_diplomes_acces_da_mention_id_foreign` FOREIGN KEY (`da_mention_id`) REFERENCES `n_mentions` (`men_id`),
  CONSTRAINT `n_diplomes_acces_da_pays_id_foreign` FOREIGN KEY (`da_pays_id`) REFERENCES `n_pays` (`pays_id`),
  CONSTRAINT `n_diplomes_acces_da_preins_id_foreign` FOREIGN KEY (`da_preins_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_diplomes_acces_da_type_diplome_id_foreign` FOREIGN KEY (`da_type_diplome_id`) REFERENCES `n_types_diplomes_acces` (`tda_id`),
  CONSTRAINT `n_diplomes_acces_da_ville_id_foreign` FOREIGN KEY (`da_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_diplomes_impressions
DROP TABLE IF EXISTS `n_diplomes_impressions`;
CREATE TABLE `n_diplomes_impressions` (
  `dimp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dimp_dplm_id` bigint unsigned NOT NULL,
  `dimp_type` enum('original','reimpression','duplicata') COLLATE utf8mb4_unicode_ci NOT NULL,
  `dimp_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dimp_mol_id` bigint unsigned DEFAULT NULL,
  `dimp_par` bigint unsigned DEFAULT NULL,
  `dimp_le` timestamp NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dimp_id`),
  KEY `n_diplomes_impressions_dimp_mol_id_foreign` (`dimp_mol_id`),
  KEY `n_diplomes_impressions_dimp_par_foreign` (`dimp_par`),
  KEY `n_diplomes_impressions_dimp_dplm_id_dimp_le_index` (`dimp_dplm_id`,`dimp_le`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_diplomes_impressions_dimp_dplm_id_foreign` FOREIGN KEY (`dimp_dplm_id`) REFERENCES `n_diplomes_laureats` (`dplm_id`) ON DELETE CASCADE,
  CONSTRAINT `n_diplomes_impressions_dimp_mol_id_foreign` FOREIGN KEY (`dimp_mol_id`) REFERENCES `n_modeles_diplomes` (`mol_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_impressions_dimp_par_foreign` FOREIGN KEY (`dimp_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_diplomes_laureats
DROP TABLE IF EXISTS `n_diplomes_laureats`;
CREATE TABLE `n_diplomes_laureats` (
  `dplm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dplm_inscription_id` bigint unsigned NOT NULL,
  `dplm_del_id` bigint unsigned DEFAULT NULL,
  `dplm_liste_id` bigint unsigned DEFAULT NULL,
  `dplm_num_id` bigint unsigned DEFAULT NULL,
  `dplm_numero` int unsigned DEFAULT NULL,
  `dplm_mol_id` bigint unsigned DEFAULT NULL,
  `dplm_statut` enum('a_imprimer','imprime','pret','remis') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'a_imprimer',
  `dplm_moyenne` decimal(5,2) DEFAULT NULL,
  `dplm_mention` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dplm_rang` smallint unsigned DEFAULT NULL,
  `dplm_date_obtention` date DEFAULT NULL,
  `dplm_imprime_le` timestamp NULL DEFAULT NULL,
  `dplm_imprime_par` bigint unsigned DEFAULT NULL,
  `dplm_livre_le` timestamp NULL DEFAULT NULL,
  `dplm_fichier_id` bigint unsigned DEFAULT NULL,
  `dplm_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `dplm_numerote_le` timestamp NULL DEFAULT NULL,
  `dplm_numerote_par` bigint unsigned DEFAULT NULL,
  `dplm_nb_impressions` smallint unsigned NOT NULL DEFAULT '0',
  `dplm_est_duplicata` tinyint(1) NOT NULL DEFAULT '0',
  `dplm_nb_duplicatas` smallint unsigned NOT NULL DEFAULT '0',
  `dplm_pret_le` timestamp NULL DEFAULT NULL,
  `dplm_notifie_le` timestamp NULL DEFAULT NULL,
  `dplm_remis_a` enum('etudiant','mandataire') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dplm_mandataire_nom` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dplm_mandataire_piece` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dplm_remise_remarque` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dplm_remis_par` bigint unsigned DEFAULT NULL,
  `dplm_decharge_fichier_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dplm_id`),
  UNIQUE KEY `n_diplomes_laureats_dplm_inscription_id_unique` (`dplm_inscription_id`),
  UNIQUE KEY `n_diplomes_laureats_dplm_num_id_dplm_numero_unique` (`dplm_num_id`,`dplm_numero`),
  KEY `n_diplomes_laureats_dplm_del_id_foreign` (`dplm_del_id`),
  KEY `n_diplomes_laureats_dplm_mol_id_foreign` (`dplm_mol_id`),
  KEY `n_diplomes_laureats_dplm_imprime_par_foreign` (`dplm_imprime_par`),
  KEY `n_diplomes_laureats_dplm_fichier_id_foreign` (`dplm_fichier_id`),
  KEY `n_diplomes_laureats_created_by_foreign` (`created_by`),
  KEY `n_diplomes_laureats_updated_by_foreign` (`updated_by`),
  KEY `n_diplomes_laureats_dplm_liste_id_foreign` (`dplm_liste_id`),
  KEY `n_diplomes_laureats_dplm_numerote_par_foreign` (`dplm_numerote_par`),
  KEY `n_diplomes_laureats_dplm_remis_par_foreign` (`dplm_remis_par`),
  KEY `n_diplomes_laureats_dplm_decharge_fichier_id_foreign` (`dplm_decharge_fichier_id`),
  KEY `n_diplomes_laureats_dplm_statut_index` (`dplm_statut`),
  CONSTRAINT `n_diplomes_laureats_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_decharge_fichier_id_foreign` FOREIGN KEY (`dplm_decharge_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_del_id_foreign` FOREIGN KEY (`dplm_del_id`) REFERENCES `n_deliberations` (`del_id`),
  CONSTRAINT `n_diplomes_laureats_dplm_fichier_id_foreign` FOREIGN KEY (`dplm_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_imprime_par_foreign` FOREIGN KEY (`dplm_imprime_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_inscription_id_foreign` FOREIGN KEY (`dplm_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_diplomes_laureats_dplm_liste_id_foreign` FOREIGN KEY (`dplm_liste_id`) REFERENCES `n_listes_laureats` (`liste_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_mol_id_foreign` FOREIGN KEY (`dplm_mol_id`) REFERENCES `n_modeles_diplomes` (`mol_id`),
  CONSTRAINT `n_diplomes_laureats_dplm_num_id_foreign` FOREIGN KEY (`dplm_num_id`) REFERENCES `n_num_diplomes` (`num_id`),
  CONSTRAINT `n_diplomes_laureats_dplm_numerote_par_foreign` FOREIGN KEY (`dplm_numerote_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_dplm_remis_par_foreign` FOREIGN KEY (`dplm_remis_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_diplomes_laureats_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_dplm_livraison` CHECK (((`dplm_livre_le` is null) or (`dplm_imprime_le` is not null))),
  CONSTRAINT `chk_dplm_numero` CHECK ((((`dplm_num_id` is null) and (`dplm_numero` is null)) or ((`dplm_num_id` is not null) and (`dplm_numero` >= 1))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_conseil_etudiants
DROP TABLE IF EXISTS `n_disc_conseil_etudiants`;
CREATE TABLE `n_disc_conseil_etudiants` (
  `ce_con_id` bigint unsigned NOT NULL,
  `ce_ins_id` bigint unsigned NOT NULL,
  `ce_inc_id` bigint unsigned DEFAULT NULL,
  `ce_convoque_le` timestamp NULL DEFAULT NULL,
  `ce_present` tinyint(1) DEFAULT NULL,
  `ce_decision` enum('sanction','aucune') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ce_san_id` bigint unsigned DEFAULT NULL,
  `ce_observations` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ce_con_id`,`ce_ins_id`),
  KEY `n_disc_conseil_etudiants_ce_ins_id_foreign` (`ce_ins_id`),
  KEY `n_disc_conseil_etudiants_ce_inc_id_foreign` (`ce_inc_id`),
  KEY `n_disc_conseil_etudiants_ce_san_id_foreign` (`ce_san_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_conseil_etudiants_ce_con_id_foreign` FOREIGN KEY (`ce_con_id`) REFERENCES `n_disc_conseils` (`con_id`) ON DELETE CASCADE,
  CONSTRAINT `n_disc_conseil_etudiants_ce_inc_id_foreign` FOREIGN KEY (`ce_inc_id`) REFERENCES `n_disc_incidents` (`inc_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_conseil_etudiants_ce_ins_id_foreign` FOREIGN KEY (`ce_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_disc_conseil_etudiants_ce_san_id_foreign` FOREIGN KEY (`ce_san_id`) REFERENCES `n_disc_sanctions` (`san_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_conseil_membres
DROP TABLE IF EXISTS `n_disc_conseil_membres`;
CREATE TABLE `n_disc_conseil_membres` (
  `cm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `cm_con_id` bigint unsigned NOT NULL,
  `cm_user_id` bigint unsigned DEFAULT NULL,
  `cm_nom` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `cm_qualite` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`cm_id`),
  KEY `n_disc_conseil_membres_cm_con_id_foreign` (`cm_con_id`),
  KEY `n_disc_conseil_membres_cm_user_id_foreign` (`cm_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_conseil_membres_cm_con_id_foreign` FOREIGN KEY (`cm_con_id`) REFERENCES `n_disc_conseils` (`con_id`) ON DELETE CASCADE,
  CONSTRAINT `n_disc_conseil_membres_cm_user_id_foreign` FOREIGN KEY (`cm_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_conseils
DROP TABLE IF EXISTS `n_disc_conseils`;
CREATE TABLE `n_disc_conseils` (
  `con_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `con_centre_id` bigint unsigned NOT NULL,
  `con_date` datetime NOT NULL,
  `con_lieu` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `con_statut` enum('planifie','tenu','annule') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'planifie',
  `con_pv` mediumtext COLLATE utf8mb4_unicode_ci,
  `con_convocations_le` timestamp NULL DEFAULT NULL,
  `con_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`con_id`),
  KEY `n_disc_conseils_con_cree_par_foreign` (`con_cree_par`),
  KEY `n_disc_conseils_con_centre_id_con_date_index` (`con_centre_id`,`con_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_conseils_con_centre_id_foreign` FOREIGN KEY (`con_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_disc_conseils_con_cree_par_foreign` FOREIGN KEY (`con_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_incident_fichiers
DROP TABLE IF EXISTS `n_disc_incident_fichiers`;
CREATE TABLE `n_disc_incident_fichiers` (
  `dif_inc_id` bigint unsigned NOT NULL,
  `dif_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dif_inc_id`,`dif_fichier_id`),
  KEY `n_disc_incident_fichiers_dif_fichier_id_foreign` (`dif_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_incident_fichiers_dif_fichier_id_foreign` FOREIGN KEY (`dif_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_disc_incident_fichiers_dif_inc_id_foreign` FOREIGN KEY (`dif_inc_id`) REFERENCES `n_disc_incidents` (`inc_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_incidents
DROP TABLE IF EXISTS `n_disc_incidents`;
CREATE TABLE `n_disc_incidents` (
  `inc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inc_ins_id` bigint unsigned NOT NULL,
  `inc_date` date NOT NULL,
  `inc_type` enum('absences','retards','comportement','fraude','degradation','autre') COLLATE utf8mb4_unicode_ci NOT NULL,
  `inc_description` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `inc_temoins` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `inc_emo_id` bigint unsigned DEFAULT NULL,
  `inc_exam_id` bigint unsigned DEFAULT NULL,
  `inc_statut` enum('signale','instruit','classe','sanctionne','renvoye_conseil') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'signale',
  `inc_note_interne` text COLLATE utf8mb4_unicode_ci,
  `inc_motif_classement` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `inc_signale_par` bigint unsigned DEFAULT NULL,
  `inc_prof_id` bigint unsigned DEFAULT NULL,
  `inc_instruit_par` bigint unsigned DEFAULT NULL,
  `inc_instruit_le` timestamp NULL DEFAULT NULL,
  `inc_conseil_id` bigint unsigned DEFAULT NULL,
  `inc_seuil_module_id` bigint unsigned DEFAULT NULL,
  `inc_seuil_niveau` enum('oral','ecrit','conseil') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`inc_id`),
  UNIQUE KEY `uq_inc_seuil` (`inc_ins_id`,`inc_seuil_module_id`,`inc_seuil_niveau`),
  KEY `n_disc_incidents_inc_emo_id_foreign` (`inc_emo_id`),
  KEY `n_disc_incidents_inc_exam_id_foreign` (`inc_exam_id`),
  KEY `n_disc_incidents_inc_signale_par_foreign` (`inc_signale_par`),
  KEY `n_disc_incidents_inc_prof_id_foreign` (`inc_prof_id`),
  KEY `n_disc_incidents_inc_instruit_par_foreign` (`inc_instruit_par`),
  KEY `n_disc_incidents_inc_conseil_id_foreign` (`inc_conseil_id`),
  KEY `n_disc_incidents_inc_seuil_module_id_foreign` (`inc_seuil_module_id`),
  KEY `n_disc_incidents_inc_statut_inc_date_index` (`inc_statut`,`inc_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_incidents_inc_conseil_id_foreign` FOREIGN KEY (`inc_conseil_id`) REFERENCES `n_disc_conseils` (`con_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_incidents_inc_emo_id_foreign` FOREIGN KEY (`inc_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_incidents_inc_exam_id_foreign` FOREIGN KEY (`inc_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_incidents_inc_ins_id_foreign` FOREIGN KEY (`inc_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_disc_incidents_inc_instruit_par_foreign` FOREIGN KEY (`inc_instruit_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_incidents_inc_prof_id_foreign` FOREIGN KEY (`inc_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_incidents_inc_seuil_module_id_foreign` FOREIGN KEY (`inc_seuil_module_id`) REFERENCES `n_modules` (`mod_id`),
  CONSTRAINT `n_disc_incidents_inc_signale_par_foreign` FOREIGN KEY (`inc_signale_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disc_sanctions
DROP TABLE IF EXISTS `n_disc_sanctions`;
CREATE TABLE `n_disc_sanctions` (
  `san_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `san_ins_id` bigint unsigned NOT NULL,
  `san_inc_id` bigint unsigned DEFAULT NULL,
  `san_conseil_id` bigint unsigned DEFAULT NULL,
  `san_type` enum('avertissement_oral','avertissement_ecrit','blame','exclusion_temporaire','exclusion_definitive','annulation_examen') COLLATE utf8mb4_unicode_ci NOT NULL,
  `san_date_decision` date NOT NULL,
  `san_decide_par` bigint unsigned DEFAULT NULL,
  `san_autorite` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `san_motif` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `san_nb_jours` smallint unsigned DEFAULT NULL,
  `san_date_debut` date DEFAULT NULL,
  `san_date_fin` date DEFAULT NULL,
  `san_exam_id` bigint unsigned DEFAULT NULL,
  `san_notifiee_le` timestamp NULL DEFAULT NULL,
  `san_abandon_le` timestamp NULL DEFAULT NULL,
  `san_annulee_le` timestamp NULL DEFAULT NULL,
  `san_motif_annulation` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`san_id`),
  KEY `n_disc_sanctions_san_inc_id_foreign` (`san_inc_id`),
  KEY `n_disc_sanctions_san_conseil_id_foreign` (`san_conseil_id`),
  KEY `n_disc_sanctions_san_decide_par_foreign` (`san_decide_par`),
  KEY `n_disc_sanctions_san_exam_id_foreign` (`san_exam_id`),
  KEY `n_disc_sanctions_san_ins_id_san_date_decision_index` (`san_ins_id`,`san_date_decision`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disc_sanctions_san_conseil_id_foreign` FOREIGN KEY (`san_conseil_id`) REFERENCES `n_disc_conseils` (`con_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_sanctions_san_decide_par_foreign` FOREIGN KEY (`san_decide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_sanctions_san_exam_id_foreign` FOREIGN KEY (`san_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_sanctions_san_inc_id_foreign` FOREIGN KEY (`san_inc_id`) REFERENCES `n_disc_incidents` (`inc_id`) ON DELETE SET NULL,
  CONSTRAINT `n_disc_sanctions_san_ins_id_foreign` FOREIGN KEY (`san_ins_id`) REFERENCES `n_inscriptions` (`ins_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_disponibilites_enseignants
DROP TABLE IF EXISTS `n_disponibilites_enseignants`;
CREATE TABLE `n_disponibilites_enseignants` (
  `de_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `de_prof_id` bigint unsigned NOT NULL,
  `de_as_id` bigint unsigned NOT NULL,
  `de_centre_id` bigint unsigned DEFAULT NULL,
  `de_jour` tinyint unsigned NOT NULL,
  `de_heure_debut` time NOT NULL,
  `de_heure_fin` time NOT NULL,
  `de_type` enum('disponible','indisponible') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'disponible',
  `de_date_debut` date DEFAULT NULL,
  `de_date_fin` date DEFAULT NULL,
  `de_commentaire` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`de_id`),
  KEY `n_disponibilites_enseignants_de_as_id_foreign` (`de_as_id`),
  KEY `n_disponibilites_enseignants_de_centre_id_foreign` (`de_centre_id`),
  KEY `n_disponibilites_enseignants_de_prof_id_de_as_id_de_jour_index` (`de_prof_id`,`de_as_id`,`de_jour`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_disponibilites_enseignants_de_as_id_foreign` FOREIGN KEY (`de_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_disponibilites_enseignants_de_centre_id_foreign` FOREIGN KEY (`de_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_disponibilites_enseignants_de_prof_id_foreign` FOREIGN KEY (`de_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_de_dates` CHECK (((`de_date_fin` is null) or (`de_date_debut` is null) or (`de_date_fin` >= `de_date_debut`))),
  CONSTRAINT `chk_de_heures` CHECK ((`de_heure_fin` > `de_heure_debut`)),
  CONSTRAINT `chk_de_jour` CHECK ((`de_jour` between 1 and 7))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_documents_delivres
DROP TABLE IF EXISTS `n_documents_delivres`;
CREATE TABLE `n_documents_delivres` (
  `dd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dd_reference` char(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dd_etud_id` bigint unsigned NOT NULL,
  `dd_ins_id` bigint unsigned DEFAULT NULL,
  `dd_dem_id` bigint unsigned DEFAULT NULL,
  `dd_typedoc_id` bigint unsigned NOT NULL,
  `dd_mdoc_id` bigint unsigned DEFAULT NULL,
  `dd_titre` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dd_contenu` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dd_delivre_par` bigint unsigned DEFAULT NULL,
  `dd_delivre_le` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `dd_annule_le` timestamp NULL DEFAULT NULL,
  `dd_annule_motif` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dd_id`),
  UNIQUE KEY `n_documents_delivres_dd_reference_unique` (`dd_reference`),
  KEY `n_documents_delivres_dd_ins_id_foreign` (`dd_ins_id`),
  KEY `n_documents_delivres_dd_dem_id_foreign` (`dd_dem_id`),
  KEY `n_documents_delivres_dd_typedoc_id_foreign` (`dd_typedoc_id`),
  KEY `n_documents_delivres_dd_mdoc_id_foreign` (`dd_mdoc_id`),
  KEY `n_documents_delivres_dd_delivre_par_foreign` (`dd_delivre_par`),
  KEY `n_documents_delivres_dd_etud_id_dd_delivre_le_index` (`dd_etud_id`,`dd_delivre_le`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_documents_delivres_dd_delivre_par_foreign` FOREIGN KEY (`dd_delivre_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_documents_delivres_dd_dem_id_foreign` FOREIGN KEY (`dd_dem_id`) REFERENCES `n_demandes` (`dem_id`) ON DELETE SET NULL,
  CONSTRAINT `n_documents_delivres_dd_etud_id_foreign` FOREIGN KEY (`dd_etud_id`) REFERENCES `n_etudiants` (`etud_id`),
  CONSTRAINT `n_documents_delivres_dd_ins_id_foreign` FOREIGN KEY (`dd_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_documents_delivres_dd_mdoc_id_foreign` FOREIGN KEY (`dd_mdoc_id`) REFERENCES `n_modeles_documents` (`mdoc_id`) ON DELETE SET NULL,
  CONSTRAINT `n_documents_delivres_dd_typedoc_id_foreign` FOREIGN KEY (`dd_typedoc_id`) REFERENCES `n_types_documents` (`tdoc_id`),
  CONSTRAINT `chk_dd_annulation` CHECK (((`dd_annule_le` is null) or (`dd_annule_motif` is not null)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_domaines
DROP TABLE IF EXISTS `n_domaines`;
CREATE TABLE `n_domaines` (
  `dom_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dom_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dom_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dom_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `dom_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dom_id`),
  UNIQUE KEY `n_domaines_dom_nom_unique` (`dom_nom`),
  UNIQUE KEY `n_domaines_dom_code_unique` (`dom_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_domaines_uf
DROP TABLE IF EXISTS `n_domaines_uf`;
CREATE TABLE `n_domaines_uf` (
  `duf_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `duf_nom` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `duf_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`duf_id`),
  UNIQUE KEY `n_domaines_uf_duf_nom_unique` (`duf_nom`),
  KEY `n_domaines_uf_created_by_index` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_dossiers_acceptation
DROP TABLE IF EXISTS `n_dossiers_acceptation`;
CREATE TABLE `n_dossiers_acceptation` (
  `da_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `da_inscription_id` bigint unsigned NOT NULL,
  `da_fichier_id` bigint unsigned NOT NULL,
  `da_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`da_id`),
  UNIQUE KEY `n_dossiers_acceptation_da_inscription_id_unique` (`da_inscription_id`),
  KEY `n_dossiers_acceptation_da_fichier_id_foreign` (`da_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_dossiers_acceptation_da_fichier_id_foreign` FOREIGN KEY (`da_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_dossiers_acceptation_da_inscription_id_foreign` FOREIGN KEY (`da_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_edt
DROP TABLE IF EXISTS `n_edt`;
CREATE TABLE `n_edt` (
  `edt_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `edt_classe_id` bigint unsigned NOT NULL,
  `edt_as_id` bigint unsigned NOT NULL,
  `edt_centre_id` bigint unsigned NOT NULL,
  `edt_site_id` bigint unsigned DEFAULT NULL,
  `edt_sem_id` bigint unsigned NOT NULL,
  `edt_type_id` bigint unsigned NOT NULL,
  `edt_mode_id` bigint unsigned NOT NULL,
  `edt_statut` enum('P','D') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'P',
  `edt_publie_le` timestamp NULL DEFAULT NULL,
  `edt_publie_par` bigint unsigned DEFAULT NULL,
  `edt_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `edt_date_validite` date DEFAULT NULL,
  `edt_type_adm` enum('M','S') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'M',
  `edt_est_decale` tinyint(1) NOT NULL DEFAULT '0',
  `edt_calender_id` bigint unsigned DEFAULT NULL,
  `edt_fichier_id` bigint unsigned DEFAULT NULL,
  `edt_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `edt_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `edt_courant_key` bigint unsigned GENERATED ALWAYS AS (if((`edt_est_decale` = 0),`edt_classe_id`,NULL)) STORED,
  PRIMARY KEY (`edt_id`),
  UNIQUE KEY `uq_edt_courant` (`edt_courant_key`,`edt_centre_id`,`edt_as_id`,`edt_sem_id`,`edt_type_id`,`edt_mode_id`,`edt_type_adm`),
  KEY `n_edt_edt_classe_id_foreign` (`edt_classe_id`),
  KEY `n_edt_edt_centre_id_foreign` (`edt_centre_id`),
  KEY `fk_edt_site_centre` (`edt_site_id`,`edt_centre_id`),
  KEY `n_edt_edt_sem_id_foreign` (`edt_sem_id`),
  KEY `n_edt_edt_type_id_foreign` (`edt_type_id`),
  KEY `n_edt_edt_mode_id_foreign` (`edt_mode_id`),
  KEY `n_edt_edt_calender_id_foreign` (`edt_calender_id`),
  KEY `n_edt_edt_fichier_id_foreign` (`edt_fichier_id`),
  KEY `n_edt_edt_as_id_edt_classe_id_index` (`edt_as_id`,`edt_classe_id`),
  KEY `n_edt_created_by_foreign` (`created_by`),
  KEY `n_edt_updated_by_foreign` (`updated_by`),
  KEY `n_edt_edt_publie_par_foreign` (`edt_publie_par`),
  CONSTRAINT `fk_edt_site_centre` FOREIGN KEY (`edt_site_id`, `edt_centre_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_edt_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_edt_edt_as_id_foreign` FOREIGN KEY (`edt_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_edt_edt_calender_id_foreign` FOREIGN KEY (`edt_calender_id`) REFERENCES `n_calendrier_pedagogiques` (`cal_id`),
  CONSTRAINT `n_edt_edt_centre_id_foreign` FOREIGN KEY (`edt_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_edt_edt_classe_id_foreign` FOREIGN KEY (`edt_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_edt_edt_fichier_id_foreign` FOREIGN KEY (`edt_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_edt_edt_mode_id_foreign` FOREIGN KEY (`edt_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_edt_edt_publie_par_foreign` FOREIGN KEY (`edt_publie_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_edt_edt_sem_id_foreign` FOREIGN KEY (`edt_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `n_edt_edt_type_id_foreign` FOREIGN KEY (`edt_type_id`) REFERENCES `n_type_edt` (`edtype_id`),
  CONSTRAINT `n_edt_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_edt_unites
DROP TABLE IF EXISTS `n_edt_unites`;
CREATE TABLE `n_edt_unites` (
  `uet_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uet_edt_id` bigint unsigned NOT NULL,
  `uet_emo_id` bigint unsigned NOT NULL,
  `uet_type_edt_id` bigint unsigned DEFAULT NULL,
  `uet_prof_id` bigint unsigned NOT NULL,
  `uet_groupe_id` bigint unsigned DEFAULT NULL,
  `uet_jour` tinyint unsigned NOT NULL,
  `uet_hdeb` time NOT NULL,
  `uet_hfin` time NOT NULL,
  `uet_duree_min` smallint unsigned GENERATED ALWAYS AS (((time_to_sec(`uet_hfin`) - time_to_sec(`uet_hdeb`)) DIV 60)) STORED,
  `uet_date_deb` date NOT NULL,
  `uet_date_fin` date NOT NULL,
  `uet_est_en_ligne` tinyint(1) NOT NULL DEFAULT '0',
  `uet_lien_visio` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uet_remarque` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uet_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`uet_id`),
  KEY `n_edt_unites_uet_edt_id_foreign` (`uet_edt_id`),
  KEY `n_edt_unites_uet_emo_id_foreign` (`uet_emo_id`),
  KEY `n_edt_unites_uet_groupe_id_foreign` (`uet_groupe_id`),
  KEY `n_edt_unites_uet_prof_id_uet_jour_index` (`uet_prof_id`,`uet_jour`),
  KEY `n_edt_unites_uet_type_edt_id_foreign` (`uet_type_edt_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_edt_unites_uet_edt_id_foreign` FOREIGN KEY (`uet_edt_id`) REFERENCES `n_edt` (`edt_id`) ON DELETE CASCADE,
  CONSTRAINT `n_edt_unites_uet_emo_id_foreign` FOREIGN KEY (`uet_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_edt_unites_uet_groupe_id_foreign` FOREIGN KEY (`uet_groupe_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_edt_unites_uet_prof_id_foreign` FOREIGN KEY (`uet_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_edt_unites_uet_type_edt_id_foreign` FOREIGN KEY (`uet_type_edt_id`) REFERENCES `n_type_edt` (`edtype_id`),
  CONSTRAINT `chk_uet_dates` CHECK ((`uet_date_fin` >= `uet_date_deb`)),
  CONSTRAINT `chk_uet_heures` CHECK ((`uet_hfin` > `uet_hdeb`)),
  CONSTRAINT `chk_uet_jour` CHECK ((`uet_jour` between 1 and 7))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_element_affectations
DROP TABLE IF EXISTS `n_element_affectations`;
CREATE TABLE `n_element_affectations` (
  `aff_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `aff_emo_id` bigint unsigned NOT NULL,
  `aff_groupe_id` bigint unsigned DEFAULT NULL,
  `aff_periode` enum('jour','soir') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aff_role` enum('cours','TD','TP') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'cours',
  `aff_prof_id` bigint unsigned NOT NULL,
  `aff_nbh` decimal(5,2) DEFAULT NULL,
  `aff_groupe_key` bigint unsigned GENERATED ALWAYS AS (coalesce(`aff_groupe_id`,0)) STORED,
  `aff_periode_key` varchar(5) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS (coalesce(`aff_periode`,'')) STORED,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`aff_id`),
  UNIQUE KEY `uq_aff_element` (`aff_emo_id`,`aff_groupe_key`,`aff_periode_key`,`aff_role`),
  KEY `n_element_affectations_aff_prof_id_index` (`aff_prof_id`),
  KEY `n_element_affectations_aff_groupe_id_foreign` (`aff_groupe_id`),
  KEY `n_element_affectations_created_by_index` (`created_by`),
  CONSTRAINT `n_element_affectations_aff_emo_id_foreign` FOREIGN KEY (`aff_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_element_affectations_aff_groupe_id_foreign` FOREIGN KEY (`aff_groupe_id`) REFERENCES `n_groupes` (`grp_id`),
  CONSTRAINT `n_element_affectations_aff_prof_id_foreign` FOREIGN KEY (`aff_prof_id`) REFERENCES `n_enseignants` (`prof_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_elements_modules
DROP TABLE IF EXISTS `n_elements_modules`;
CREATE TABLE `n_elements_modules` (
  `emo_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `emo_classe_id` bigint unsigned NOT NULL,
  `emo_mod_id` bigint unsigned DEFAULT NULL,
  `emo_mod_index` smallint unsigned NOT NULL,
  `emo_mat_id` bigint unsigned NOT NULL,
  `emo_sem_id` bigint unsigned DEFAULT NULL,
  `emo_prof_cours_id` bigint unsigned DEFAULT NULL,
  `emo_prof_td_id` bigint unsigned DEFAULT NULL,
  `emo_prof_p_id` bigint unsigned DEFAULT NULL,
  `emo_prof_h_id` bigint unsigned DEFAULT NULL,
  `emo_coef` decimal(5,2) NOT NULL,
  `emo_nb_heures` decimal(5,2) NOT NULL,
  `emo_heures_cm` decimal(5,2) DEFAULT NULL,
  `emo_heures_td` decimal(5,2) DEFAULT NULL,
  `emo_heures_tp` decimal(5,2) DEFAULT NULL,
  `emo_type` enum('MOD','PFE','PFA','U.F','Stage','TI') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'U.F',
  `emo_est_visible_pv` tinyint(1) NOT NULL DEFAULT '1',
  `emo_est_enseigne` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `emo_uf_id` bigint unsigned DEFAULT NULL,
  `emo_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`emo_id`),
  UNIQUE KEY `uq_emo_classe_sem_mod_mat` (`emo_classe_id`,`emo_sem_id`,`emo_mod_id`,`emo_mat_id`),
  KEY `n_elements_modules_emo_mod_id_foreign` (`emo_mod_id`),
  KEY `n_elements_modules_emo_mat_id_foreign` (`emo_mat_id`),
  KEY `n_elements_modules_emo_sem_id_foreign` (`emo_sem_id`),
  KEY `n_elements_modules_emo_prof_cours_id_foreign` (`emo_prof_cours_id`),
  KEY `n_elements_modules_emo_prof_td_id_foreign` (`emo_prof_td_id`),
  KEY `n_elements_modules_emo_prof_p_id_foreign` (`emo_prof_p_id`),
  KEY `n_elements_modules_emo_prof_h_id_foreign` (`emo_prof_h_id`),
  KEY `n_elements_modules_created_by_foreign` (`created_by`),
  KEY `n_elements_modules_updated_by_foreign` (`updated_by`),
  KEY `n_elements_modules_emo_uf_id_index` (`emo_uf_id`),
  CONSTRAINT `n_elements_modules_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_elements_modules_emo_classe_id_foreign` FOREIGN KEY (`emo_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_elements_modules_emo_mat_id_foreign` FOREIGN KEY (`emo_mat_id`) REFERENCES `n_matieres` (`mat_id`),
  CONSTRAINT `n_elements_modules_emo_mod_id_foreign` FOREIGN KEY (`emo_mod_id`) REFERENCES `n_modules` (`mod_id`),
  CONSTRAINT `n_elements_modules_emo_prof_cours_id_foreign` FOREIGN KEY (`emo_prof_cours_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_elements_modules_emo_prof_h_id_foreign` FOREIGN KEY (`emo_prof_h_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_elements_modules_emo_prof_p_id_foreign` FOREIGN KEY (`emo_prof_p_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_elements_modules_emo_prof_td_id_foreign` FOREIGN KEY (`emo_prof_td_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_elements_modules_emo_sem_id_foreign` FOREIGN KEY (`emo_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `n_elements_modules_emo_uf_id_foreign` FOREIGN KEY (`emo_uf_id`) REFERENCES `n_unites_formation` (`uf_id`),
  CONSTRAINT `n_elements_modules_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_emo_coef` CHECK ((`emo_coef` between 0 and 100)),
  CONSTRAINT `chk_emo_mod_index` CHECK ((`emo_mod_index` >= 1)),
  CONSTRAINT `chk_emo_nb_heures` CHECK ((`emo_nb_heures` > 0)),
  CONSTRAINT `chk_emo_ventilation` CHECK ((((`emo_heures_cm` is null) or (`emo_heures_cm` >= 0)) and ((`emo_heures_td` is null) or (`emo_heures_td` >= 0)) and ((`emo_heures_tp` is null) or (`emo_heures_tp` >= 0))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_encadrants_projets
DROP TABLE IF EXISTS `n_encadrants_projets`;
CREATE TABLE `n_encadrants_projets` (
  `ep_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ep_emo_id` bigint unsigned NOT NULL,
  `ep_gp_id` bigint unsigned NOT NULL,
  `ep_prof_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ep_id`),
  UNIQUE KEY `uq_ep_emo_gp_prof` (`ep_emo_id`,`ep_gp_id`,`ep_prof_id`),
  KEY `n_encadrants_projets_ep_gp_id_foreign` (`ep_gp_id`),
  KEY `n_encadrants_projets_ep_prof_id_foreign` (`ep_prof_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_encadrants_projets_ep_emo_id_foreign` FOREIGN KEY (`ep_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_encadrants_projets_ep_gp_id_foreign` FOREIGN KEY (`ep_gp_id`) REFERENCES `n_groupes_projets` (`gp_id`) ON DELETE CASCADE,
  CONSTRAINT `n_encadrants_projets_ep_prof_id_foreign` FOREIGN KEY (`ep_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_enquete_invites
DROP TABLE IF EXISTS `n_enquete_invites`;
CREATE TABLE `n_enquete_invites` (
  `ei_enq_id` bigint unsigned NOT NULL,
  `ei_ins_id` bigint unsigned NOT NULL,
  `ei_user_id` bigint unsigned DEFAULT NULL,
  `ei_notifie_le` timestamp NULL DEFAULT NULL,
  `ei_repondu_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ei_enq_id`,`ei_ins_id`),
  KEY `n_enquete_invites_ei_ins_id_foreign` (`ei_ins_id`),
  KEY `n_enquete_invites_ei_user_id_index` (`ei_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_enquete_invites_ei_enq_id_foreign` FOREIGN KEY (`ei_enq_id`) REFERENCES `n_enquetes_insertion` (`enq_id`) ON DELETE CASCADE,
  CONSTRAINT `n_enquete_invites_ei_ins_id_foreign` FOREIGN KEY (`ei_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_enquete_invites_ei_user_id_foreign` FOREIGN KEY (`ei_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_enquetes_insertion
DROP TABLE IF EXISTS `n_enquetes_insertion`;
CREATE TABLE `n_enquetes_insertion` (
  `enq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `enq_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `enq_as_id` bigint unsigned NOT NULL,
  `enq_centre_id` bigint unsigned DEFAULT NULL,
  `enq_formation_id` bigint unsigned DEFAULT NULL,
  `enq_ouverture` date NOT NULL,
  `enq_cloture` date NOT NULL,
  `enq_message` text COLLATE utf8mb4_unicode_ci,
  `enq_nb_invites` int unsigned NOT NULL DEFAULT '0',
  `enq_envoyee_le` timestamp NULL DEFAULT NULL,
  `enq_relancee_le` timestamp NULL DEFAULT NULL,
  `enq_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`enq_id`),
  KEY `n_enquetes_insertion_enq_centre_id_foreign` (`enq_centre_id`),
  KEY `n_enquetes_insertion_enq_formation_id_foreign` (`enq_formation_id`),
  KEY `n_enquetes_insertion_enq_cree_par_foreign` (`enq_cree_par`),
  KEY `n_enquetes_insertion_enq_as_id_enq_cloture_index` (`enq_as_id`,`enq_cloture`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_enquetes_insertion_enq_as_id_foreign` FOREIGN KEY (`enq_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_enquetes_insertion_enq_centre_id_foreign` FOREIGN KEY (`enq_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_enquetes_insertion_enq_cree_par_foreign` FOREIGN KEY (`enq_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_enquetes_insertion_enq_formation_id_foreign` FOREIGN KEY (`enq_formation_id`) REFERENCES `n_formations` (`for_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_enseignant_affectations
DROP TABLE IF EXISTS `n_enseignant_affectations`;
CREATE TABLE `n_enseignant_affectations` (
  `ea_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ea_prof_id` bigint unsigned NOT NULL,
  `ea_centre_id` bigint unsigned NOT NULL,
  `ea_site_id` bigint unsigned DEFAULT NULL,
  `ea_est_principale` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `ea_site_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`ea_site_id`,0)) STORED,
  `ea_principale_key` bigint unsigned GENERATED ALWAYS AS (if((`ea_est_principale` = 1),`ea_prof_id`,NULL)) VIRTUAL,
  PRIMARY KEY (`ea_id`),
  UNIQUE KEY `uq_ea_affectation` (`ea_prof_id`,`ea_centre_id`,`ea_site_key`),
  UNIQUE KEY `uq_ea_principale` (`ea_principale_key`),
  KEY `n_enseignant_affectations_ea_centre_id_foreign` (`ea_centre_id`),
  KEY `fk_ea_site_centre` (`ea_site_id`,`ea_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `fk_ea_site_centre` FOREIGN KEY (`ea_site_id`, `ea_centre_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_enseignant_affectations_ea_centre_id_foreign` FOREIGN KEY (`ea_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_enseignant_affectations_ea_prof_id_foreign` FOREIGN KEY (`ea_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_enseignants
DROP TABLE IF EXISTS `n_enseignants`;
CREATE TABLE `n_enseignants` (
  `prof_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `prof_civilite` enum('M','MME','MLLE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `prof_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `prof_sexe` enum('M','F') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `prof_cin` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_date_naissance` date DEFAULT NULL,
  `prof_ville_naissance_id` bigint unsigned DEFAULT NULL,
  `prof_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_ville_id` bigint unsigned DEFAULT NULL,
  `prof_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_type_contrat_id` bigint unsigned NOT NULL,
  `prof_specialite` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_diplome` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `prof_date_debut_contrat` date DEFAULT NULL,
  `prof_date_fin_contrat` date DEFAULT NULL,
  `prof_taux_horaire` decimal(10,2) DEFAULT NULL,
  `prof_est_soumis_ir` tinyint(1) NOT NULL DEFAULT '0',
  `prof_taux_ir` decimal(5,2) DEFAULT NULL,
  `prof_nb_heures_ir` smallint unsigned DEFAULT NULL,
  `prof_photo_fichier_id` bigint unsigned DEFAULT NULL,
  `prof_signature_fichier_id` bigint unsigned DEFAULT NULL,
  `prof_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`prof_id`),
  UNIQUE KEY `n_enseignants_prof_cin_unique` (`prof_cin`),
  UNIQUE KEY `n_enseignants_prof_user_id_unique` (`prof_user_id`),
  KEY `n_enseignants_prof_ville_naissance_id_foreign` (`prof_ville_naissance_id`),
  KEY `n_enseignants_prof_ville_id_foreign` (`prof_ville_id`),
  KEY `n_enseignants_prof_type_contrat_id_foreign` (`prof_type_contrat_id`),
  KEY `n_enseignants_prof_photo_fichier_id_foreign` (`prof_photo_fichier_id`),
  KEY `n_enseignants_prof_signature_fichier_id_foreign` (`prof_signature_fichier_id`),
  KEY `n_enseignants_prof_nom_prof_prenom_index` (`prof_nom`,`prof_prenom`),
  KEY `n_enseignants_created_by_foreign` (`created_by`),
  KEY `n_enseignants_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_enseignants_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_enseignants_prof_photo_fichier_id_foreign` FOREIGN KEY (`prof_photo_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_enseignants_prof_signature_fichier_id_foreign` FOREIGN KEY (`prof_signature_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_enseignants_prof_type_contrat_id_foreign` FOREIGN KEY (`prof_type_contrat_id`) REFERENCES `n_types_contrats` (`tpc_id`),
  CONSTRAINT `n_enseignants_prof_user_id_foreign` FOREIGN KEY (`prof_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_enseignants_prof_ville_id_foreign` FOREIGN KEY (`prof_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_enseignants_prof_ville_naissance_id_foreign` FOREIGN KEY (`prof_ville_naissance_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_enseignants_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_prof_contrat_dates` CHECK (((`prof_date_fin_contrat` is null) or (`prof_date_debut_contrat` is null) or (`prof_date_fin_contrat` >= `prof_date_debut_contrat`))),
  CONSTRAINT `chk_prof_taux_horaire` CHECK (((`prof_taux_horaire` is null) or (`prof_taux_horaire` >= 0))),
  CONSTRAINT `chk_prof_taux_ir` CHECK (((`prof_taux_ir` is null) or (`prof_taux_ir` between 0 and 100)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_entreprise_contacts
DROP TABLE IF EXISTS `n_entreprise_contacts`;
CREATE TABLE `n_entreprise_contacts` (
  `ec_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ec_ent_id` bigint unsigned NOT NULL,
  `ec_nom` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ec_fonction` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ec_email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ec_tel` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ec_est_tuteur` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ec_id`),
  KEY `n_entreprise_contacts_ec_ent_id_foreign` (`ec_ent_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_entreprise_contacts_ec_ent_id_foreign` FOREIGN KEY (`ec_ent_id`) REFERENCES `n_entreprises` (`ent_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_entreprises
DROP TABLE IF EXISTS `n_entreprises`;
CREATE TABLE `n_entreprises` (
  `ent_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ent_raison_sociale` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ent_ice` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_secteur` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_ville_id` bigint unsigned DEFAULT NULL,
  `ent_ville` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_site_web` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ent_description` text COLLATE utf8mb4_unicode_ci,
  `ent_est_partenaire` tinyint(1) NOT NULL DEFAULT '0',
  `ent_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `ent_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ent_id`),
  UNIQUE KEY `n_entreprises_ent_ice_unique` (`ent_ice`),
  KEY `n_entreprises_ent_ville_id_foreign` (`ent_ville_id`),
  KEY `n_entreprises_ent_raison_sociale_index` (`ent_raison_sociale`),
  KEY `n_entreprises_ent_cree_par_foreign` (`ent_cree_par`),
  KEY `n_entreprises_ent_secteur_index` (`ent_secteur`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_entreprises_ent_cree_par_foreign` FOREIGN KEY (`ent_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_entreprises_ent_ville_id_foreign` FOREIGN KEY (`ent_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_etablissements
DROP TABLE IF EXISTS `n_etablissements`;
CREATE TABLE `n_etablissements` (
  `etab_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `etab_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `etab_nom` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `etab_nom_ar` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_sigle` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_forme_juridique` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_ice` char(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_rc` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_if` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_patente` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_cnss` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_autorisation_numero` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_autorisation_date` date DEFAULT NULL,
  `etab_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_ville_id` bigint unsigned DEFAULT NULL,
  `etab_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_site_web` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_directeur` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etab_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`etab_id`),
  UNIQUE KEY `n_etablissements_etab_code_unique` (`etab_code`),
  UNIQUE KEY `n_etablissements_etab_nom_unique` (`etab_nom`),
  UNIQUE KEY `n_etablissements_etab_ice_unique` (`etab_ice`),
  KEY `n_etablissements_etab_ville_id_foreign` (`etab_ville_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_etablissements_etab_ville_id_foreign` FOREIGN KEY (`etab_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_etudiants
DROP TABLE IF EXISTS `n_etudiants`;
CREATE TABLE `n_etudiants` (
  `etud_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `etud_matricule` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_civilite` enum('M','MME','MLLE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `etud_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `etud_nom_ar` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_prenom_ar` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_sexe` enum('M','F') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `etud_date_naissance` date DEFAULT NULL,
  `etud_ville_naissance_id` bigint unsigned DEFAULT NULL,
  `etud_nat_id` bigint unsigned NOT NULL,
  `etud_cin` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_passeport` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_code_massar` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_carte_sejour_expiration` date DEFAULT NULL,
  `etud_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_ville_id` bigint unsigned DEFAULT NULL,
  `etud_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `etud_est_decale` tinyint(1) NOT NULL DEFAULT '0',
  `etud_photo_fichier_id` bigint unsigned DEFAULT NULL,
  `etud_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`etud_id`),
  UNIQUE KEY `n_etudiants_etud_matricule_unique` (`etud_matricule`),
  UNIQUE KEY `n_etudiants_etud_cin_unique` (`etud_cin`),
  UNIQUE KEY `n_etudiants_etud_passeport_unique` (`etud_passeport`),
  UNIQUE KEY `n_etudiants_etud_code_massar_unique` (`etud_code_massar`),
  UNIQUE KEY `n_etudiants_etud_user_id_unique` (`etud_user_id`),
  KEY `n_etudiants_etud_ville_naissance_id_foreign` (`etud_ville_naissance_id`),
  KEY `n_etudiants_etud_nat_id_foreign` (`etud_nat_id`),
  KEY `n_etudiants_etud_ville_id_foreign` (`etud_ville_id`),
  KEY `n_etudiants_etud_photo_fichier_id_foreign` (`etud_photo_fichier_id`),
  KEY `n_etudiants_created_by_foreign` (`created_by`),
  KEY `n_etudiants_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_etudiants_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_etudiants_etud_nat_id_foreign` FOREIGN KEY (`etud_nat_id`) REFERENCES `n_nationalites` (`nat_id`),
  CONSTRAINT `n_etudiants_etud_photo_fichier_id_foreign` FOREIGN KEY (`etud_photo_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_etudiants_etud_user_id_foreign` FOREIGN KEY (`etud_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_etudiants_etud_ville_id_foreign` FOREIGN KEY (`etud_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_etudiants_etud_ville_naissance_id_foreign` FOREIGN KEY (`etud_ville_naissance_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_etudiants_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_etudiants_contacts_historique
DROP TABLE IF EXISTS `n_etudiants_contacts_historique`;
CREATE TABLE `n_etudiants_contacts_historique` (
  `ech_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ech_etud_id` bigint unsigned NOT NULL,
  `ech_methode` enum('appel','whatsapp','email','sms','visite','facebook') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ech_resultat` enum('repondu','pas_reponse','promesse_paiement','payer','rappeler','numero_incorrect') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ech_commentaire` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `ech_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ech_id`),
  KEY `n_etudiants_contacts_historique_ech_user_id_foreign` (`ech_user_id`),
  KEY `n_etudiants_contacts_historique_ech_etud_id_created_at_index` (`ech_etud_id`,`created_at`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_etudiants_contacts_historique_ech_etud_id_foreign` FOREIGN KEY (`ech_etud_id`) REFERENCES `n_etudiants` (`etud_id`) ON DELETE CASCADE,
  CONSTRAINT `n_etudiants_contacts_historique_ech_user_id_foreign` FOREIGN KEY (`ech_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_campagne_classes
DROP TABLE IF EXISTS `n_evaluation_campagne_classes`;
CREATE TABLE `n_evaluation_campagne_classes` (
  `ecc_evc_id` bigint unsigned NOT NULL,
  `ecc_classe_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ecc_evc_id`,`ecc_classe_id`),
  KEY `n_evaluation_campagne_classes_ecc_classe_id_foreign` (`ecc_classe_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_evaluation_campagne_classes_ecc_classe_id_foreign` FOREIGN KEY (`ecc_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_evaluation_campagne_classes_ecc_evc_id_foreign` FOREIGN KEY (`ecc_evc_id`) REFERENCES `n_evaluation_campagnes` (`evc_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_campagnes
DROP TABLE IF EXISTS `n_evaluation_campagnes`;
CREATE TABLE `n_evaluation_campagnes` (
  `evc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `evc_libelle` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `evc_consigne` text COLLATE utf8mb4_unicode_ci,
  `evc_as_id` bigint unsigned NOT NULL,
  `evc_sem_id` bigint unsigned DEFAULT NULL,
  `evc_centre_id` bigint unsigned DEFAULT NULL,
  `evc_date_ouverture` datetime NOT NULL,
  `evc_date_fermeture` datetime NOT NULL,
  `evc_resultats_visibles_enseignants` tinyint(1) NOT NULL DEFAULT '0',
  `evc_seuil_reponses` tinyint unsigned NOT NULL DEFAULT '5',
  `evc_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`evc_id`),
  KEY `n_evaluation_campagnes_evc_as_id_foreign` (`evc_as_id`),
  KEY `n_evaluation_campagnes_evc_sem_id_foreign` (`evc_sem_id`),
  KEY `n_evaluation_campagnes_evc_centre_id_foreign` (`evc_centre_id`),
  KEY `n_evaluation_campagnes_evc_cree_par_foreign` (`evc_cree_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_evaluation_campagnes_evc_as_id_foreign` FOREIGN KEY (`evc_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_evaluation_campagnes_evc_centre_id_foreign` FOREIGN KEY (`evc_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_evaluation_campagnes_evc_cree_par_foreign` FOREIGN KEY (`evc_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_evaluation_campagnes_evc_sem_id_foreign` FOREIGN KEY (`evc_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `chk_evc_dates` CHECK ((`evc_date_fermeture` > `evc_date_ouverture`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_modele_questions
DROP TABLE IF EXISTS `n_evaluation_modele_questions`;
CREATE TABLE `n_evaluation_modele_questions` (
  `emq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `emq_libelle` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `emq_type` enum('note_1_5','oui_non','texte') COLLATE utf8mb4_unicode_ci NOT NULL,
  `emq_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `emq_est_obligatoire` tinyint(1) NOT NULL DEFAULT '1',
  `emq_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`emq_id`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_participations
DROP TABLE IF EXISTS `n_evaluation_participations`;
CREATE TABLE `n_evaluation_participations` (
  `evp_evc_id` bigint unsigned NOT NULL,
  `evp_ins_id` bigint unsigned NOT NULL,
  `evp_emo_id` bigint unsigned NOT NULL,
  `evp_prof_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`evp_evc_id`,`evp_ins_id`,`evp_emo_id`,`evp_prof_id`),
  KEY `n_evaluation_participations_evp_ins_id_foreign` (`evp_ins_id`),
  KEY `n_evaluation_participations_evp_emo_id_foreign` (`evp_emo_id`),
  KEY `n_evaluation_participations_evp_prof_id_foreign` (`evp_prof_id`),
  KEY `idx_evp_matiere` (`evp_evc_id`,`evp_emo_id`,`evp_prof_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_evaluation_participations_evp_emo_id_foreign` FOREIGN KEY (`evp_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_evaluation_participations_evp_evc_id_foreign` FOREIGN KEY (`evp_evc_id`) REFERENCES `n_evaluation_campagnes` (`evc_id`) ON DELETE CASCADE,
  CONSTRAINT `n_evaluation_participations_evp_ins_id_foreign` FOREIGN KEY (`evp_ins_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE,
  CONSTRAINT `n_evaluation_participations_evp_prof_id_foreign` FOREIGN KEY (`evp_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_questions
DROP TABLE IF EXISTS `n_evaluation_questions`;
CREATE TABLE `n_evaluation_questions` (
  `evq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `evq_evc_id` bigint unsigned NOT NULL,
  `evq_libelle` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `evq_type` enum('note_1_5','oui_non','texte') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `evq_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `evq_est_obligatoire` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`evq_id`),
  KEY `n_evaluation_questions_evq_evc_id_foreign` (`evq_evc_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_evaluation_questions_evq_evc_id_foreign` FOREIGN KEY (`evq_evc_id`) REFERENCES `n_evaluation_campagnes` (`evc_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_evaluation_reponses
DROP TABLE IF EXISTS `n_evaluation_reponses`;
CREATE TABLE `n_evaluation_reponses` (
  `evr_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `evr_evc_id` bigint unsigned DEFAULT NULL,
  `evr_evq_id` bigint unsigned NOT NULL,
  `evr_emo_id` bigint unsigned NOT NULL,
  `evr_prof_id` bigint unsigned DEFAULT NULL,
  `evr_classe_id` bigint unsigned NOT NULL,
  `evr_note` tinyint unsigned DEFAULT NULL,
  `evr_texte` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`evr_id`),
  KEY `n_evaluation_reponses_evr_evq_id_foreign` (`evr_evq_id`),
  KEY `n_evaluation_reponses_evr_prof_id_foreign` (`evr_prof_id`),
  KEY `n_evaluation_reponses_evr_classe_id_foreign` (`evr_classe_id`),
  KEY `n_evaluation_reponses_evr_emo_id_evr_prof_id_index` (`evr_emo_id`,`evr_prof_id`),
  KEY `idx_evr_resultats` (`evr_evc_id`,`evr_prof_id`,`evr_emo_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_evaluation_reponses_evr_classe_id_foreign` FOREIGN KEY (`evr_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_evaluation_reponses_evr_emo_id_foreign` FOREIGN KEY (`evr_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_evaluation_reponses_evr_evc_id_foreign` FOREIGN KEY (`evr_evc_id`) REFERENCES `n_evaluation_campagnes` (`evc_id`) ON DELETE CASCADE,
  CONSTRAINT `n_evaluation_reponses_evr_evq_id_foreign` FOREIGN KEY (`evr_evq_id`) REFERENCES `n_evaluation_questions` (`evq_id`) ON DELETE CASCADE,
  CONSTRAINT `n_evaluation_reponses_evr_prof_id_foreign` FOREIGN KEY (`evr_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_evr_note` CHECK (((`evr_note` is null) or (`evr_note` between 0 and 5)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_examen_elements
DROP TABLE IF EXISTS `n_examen_elements`;
CREATE TABLE `n_examen_elements` (
  `ee_exam_id` bigint unsigned NOT NULL,
  `ee_emo_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ee_exam_id`,`ee_emo_id`),
  KEY `n_examen_elements_ee_emo_id_index` (`ee_emo_id`),
  KEY `n_examen_elements_created_by_index` (`created_by`),
  CONSTRAINT `n_examen_elements_ee_emo_id_foreign` FOREIGN KEY (`ee_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_examen_elements_ee_exam_id_foreign` FOREIGN KEY (`ee_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_examens
DROP TABLE IF EXISTS `n_examens`;
CREATE TABLE `n_examens` (
  `exam_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `exam_type_id` bigint unsigned NOT NULL,
  `exam_index` tinyint unsigned NOT NULL DEFAULT '1',
  `exam_prof_id` bigint unsigned DEFAULT NULL,
  `exam_emo_id` bigint unsigned NOT NULL,
  `exam_as_id` bigint unsigned NOT NULL,
  `exam_mode_id` bigint unsigned NOT NULL,
  `exam_date` datetime DEFAULT NULL,
  `exam_date_notes` datetime DEFAULT NULL,
  `exam_date_limite` date DEFAULT NULL,
  `exam_coef` decimal(7,4) DEFAULT NULL,
  `exam_remise_le` timestamp NULL DEFAULT NULL,
  `exam_remise_par` bigint unsigned DEFAULT NULL,
  `exam_seance_id` bigint unsigned DEFAULT NULL,
  `exam_fichier_id` bigint unsigned DEFAULT NULL,
  `exam_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `exam_groupe_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`exam_id`),
  UNIQUE KEY `uq_exam` (`exam_emo_id`,`exam_as_id`,`exam_type_id`,`exam_index`,`exam_mode_id`,`exam_prof_id`),
  KEY `n_examens_exam_type_id_foreign` (`exam_type_id`),
  KEY `n_examens_exam_prof_id_foreign` (`exam_prof_id`),
  KEY `n_examens_exam_as_id_foreign` (`exam_as_id`),
  KEY `n_examens_exam_mode_id_foreign` (`exam_mode_id`),
  KEY `n_examens_exam_fichier_id_foreign` (`exam_fichier_id`),
  KEY `n_examens_exam_seance_id_index` (`exam_seance_id`),
  KEY `n_examens_created_by_foreign` (`created_by`),
  KEY `n_examens_updated_by_foreign` (`updated_by`),
  KEY `n_examens_exam_remise_par_foreign` (`exam_remise_par`),
  KEY `n_examens_exam_groupe_id_index` (`exam_groupe_id`),
  CONSTRAINT `n_examens_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_as_id_foreign` FOREIGN KEY (`exam_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_examens_exam_emo_id_foreign` FOREIGN KEY (`exam_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_examens_exam_fichier_id_foreign` FOREIGN KEY (`exam_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_groupe_id_foreign` FOREIGN KEY (`exam_groupe_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_mode_id_foreign` FOREIGN KEY (`exam_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_examens_exam_prof_id_foreign` FOREIGN KEY (`exam_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_remise_par_foreign` FOREIGN KEY (`exam_remise_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_seance_id_foreign` FOREIGN KEY (`exam_seance_id`) REFERENCES `n_seances` (`se_id`) ON DELETE SET NULL,
  CONSTRAINT `n_examens_exam_type_id_foreign` FOREIGN KEY (`exam_type_id`) REFERENCES `n_types_examens` (`tpe_id`),
  CONSTRAINT `n_examens_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_exam_coef` CHECK (((`exam_coef` is null) or (`exam_coef` between 0 and 1))),
  CONSTRAINT `chk_exam_index` CHECK ((`exam_index` between 1 and 20))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_fichiers
DROP TABLE IF EXISTS `n_fichiers`;
CREATE TABLE `n_fichiers` (
  `fic_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `fic_uuid` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fic_disque` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'local',
  `fic_chemin` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fic_nom_origine` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fic_type_mime` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fic_taille_octets` bigint unsigned NOT NULL,
  `fic_empreinte_sha256` char(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fic_visibilite` enum('prive','interne','public') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'prive',
  `fic_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`fic_id`),
  UNIQUE KEY `n_fichiers_fic_uuid_unique` (`fic_uuid`),
  UNIQUE KEY `n_fichiers_fic_chemin_unique` (`fic_chemin`),
  KEY `n_fichiers_fic_cree_par_foreign` (`fic_cree_par`),
  KEY `n_fichiers_fic_empreinte_sha256_index` (`fic_empreinte_sha256`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_fichiers_fic_cree_par_foreign` FOREIGN KEY (`fic_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_filiere_signataires
DROP TABLE IF EXISTS `n_filiere_signataires`;
CREATE TABLE `n_filiere_signataires` (
  `fs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `fs_filiere_id` bigint unsigned NOT NULL,
  `fs_prof_id` bigint unsigned NOT NULL,
  `fs_diplome_id` bigint unsigned DEFAULT NULL,
  `fs_qualite` enum('CD','CF','PR') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`fs_id`),
  UNIQUE KEY `uq_fs` (`fs_prof_id`,`fs_filiere_id`,`fs_diplome_id`,`fs_qualite`),
  KEY `n_filiere_signataires_fs_filiere_id_foreign` (`fs_filiere_id`),
  KEY `n_filiere_signataires_fs_diplome_id_foreign` (`fs_diplome_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_filiere_signataires_fs_diplome_id_foreign` FOREIGN KEY (`fs_diplome_id`) REFERENCES `n_diplomes` (`dip_id`) ON DELETE CASCADE,
  CONSTRAINT `n_filiere_signataires_fs_filiere_id_foreign` FOREIGN KEY (`fs_filiere_id`) REFERENCES `n_filieres` (`fil_id`) ON DELETE CASCADE,
  CONSTRAINT `n_filiere_signataires_fs_prof_id_foreign` FOREIGN KEY (`fs_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_filieres
DROP TABLE IF EXISTS `n_filieres`;
CREATE TABLE `n_filieres` (
  `fil_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `fil_abbr` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fil_nom` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `fil_nom_ar` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fil_dom_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`fil_id`),
  UNIQUE KEY `n_filieres_fil_abbr_unique` (`fil_abbr`),
  KEY `n_filieres_fil_dom_id_foreign` (`fil_dom_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_filieres_fil_dom_id_foreign` FOREIGN KEY (`fil_dom_id`) REFERENCES `n_domaines` (`dom_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_formations
DROP TABLE IF EXISTS `n_formations`;
CREATE TABLE `n_formations` (
  `for_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `for_centre_id` bigint unsigned NOT NULL,
  `for_abbr` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `for_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `for_diplome_id` bigint unsigned NOT NULL,
  `for_filiere_id` bigint unsigned NOT NULL,
  `for_option_id` bigint unsigned DEFAULT NULL,
  `for_est_accreditee` tinyint(1) NOT NULL DEFAULT '1',
  `for_langue` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
  `for_code_filiere` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `for_code_option` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `for_as_debut_id` bigint unsigned NOT NULL,
  `for_as_fin_id` bigint unsigned DEFAULT NULL,
  `for_accreditation_debut_id` bigint unsigned DEFAULT NULL,
  `for_accreditation_fin_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `for_profil_eval_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`for_id`),
  UNIQUE KEY `n_formations_for_centre_id_for_abbr_unique` (`for_centre_id`,`for_abbr`),
  UNIQUE KEY `uq_formation_centre` (`for_id`,`for_centre_id`),
  KEY `n_formations_for_diplome_id_foreign` (`for_diplome_id`),
  KEY `n_formations_for_filiere_id_foreign` (`for_filiere_id`),
  KEY `n_formations_for_option_id_foreign` (`for_option_id`),
  KEY `n_formations_for_as_debut_id_foreign` (`for_as_debut_id`),
  KEY `n_formations_for_as_fin_id_foreign` (`for_as_fin_id`),
  KEY `n_formations_for_accreditation_debut_id_foreign` (`for_accreditation_debut_id`),
  KEY `n_formations_for_accreditation_fin_id_foreign` (`for_accreditation_fin_id`),
  KEY `n_formations_created_by_foreign` (`created_by`),
  KEY `n_formations_updated_by_foreign` (`updated_by`),
  KEY `n_formations_for_profil_eval_id_index` (`for_profil_eval_id`),
  CONSTRAINT `n_formations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_formations_for_accreditation_debut_id_foreign` FOREIGN KEY (`for_accreditation_debut_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_formations_for_accreditation_fin_id_foreign` FOREIGN KEY (`for_accreditation_fin_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_formations_for_as_debut_id_foreign` FOREIGN KEY (`for_as_debut_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_formations_for_as_fin_id_foreign` FOREIGN KEY (`for_as_fin_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_formations_for_centre_id_foreign` FOREIGN KEY (`for_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_formations_for_diplome_id_foreign` FOREIGN KEY (`for_diplome_id`) REFERENCES `n_diplomes` (`dip_id`),
  CONSTRAINT `n_formations_for_filiere_id_foreign` FOREIGN KEY (`for_filiere_id`) REFERENCES `n_filieres` (`fil_id`),
  CONSTRAINT `n_formations_for_option_id_foreign` FOREIGN KEY (`for_option_id`) REFERENCES `n_options` (`opt_id`),
  CONSTRAINT `n_formations_for_profil_eval_id_foreign` FOREIGN KEY (`for_profil_eval_id`) REFERENCES `n_profils_evaluation` (`pev_id`) ON DELETE SET NULL,
  CONSTRAINT `n_formations_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_frais_modifications
DROP TABLE IF EXISTS `n_frais_modifications`;
CREATE TABLE `n_frais_modifications` (
  `fm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `fm_fcv_id` bigint unsigned NOT NULL,
  `fm_montant_avant` decimal(12,2) NOT NULL,
  `fm_montant_apres` decimal(12,2) NOT NULL,
  `fm_motif` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `fm_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`fm_id`),
  KEY `n_frais_modifications_fm_fcv_id_foreign` (`fm_fcv_id`),
  KEY `n_frais_modifications_fm_user_id_foreign` (`fm_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_frais_modifications_fm_fcv_id_foreign` FOREIGN KEY (`fm_fcv_id`) REFERENCES `n_fraisconvenu` (`fcv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_frais_modifications_fm_user_id_foreign` FOREIGN KEY (`fm_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_fraisconvenu
DROP TABLE IF EXISTS `n_fraisconvenu`;
CREATE TABLE `n_fraisconvenu` (
  `fcv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `fcv_ins_id` bigint unsigned NOT NULL,
  `fcv_typefrais_id` bigint unsigned NOT NULL,
  `fcv_typeperiode_id` bigint unsigned NOT NULL,
  `fcv_montant` decimal(12,2) NOT NULL,
  `fcv_devise` char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'MAD',
  `fcv_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `fcv_plp_id` bigint unsigned DEFAULT NULL,
  `fcv_date_debut` date DEFAULT NULL,
  `fcv_date_fin` date DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`fcv_id`),
  UNIQUE KEY `n_fraisconvenu_fcv_ins_id_fcv_typefrais_id_unique` (`fcv_ins_id`,`fcv_typefrais_id`),
  KEY `n_fraisconvenu_fcv_typefrais_id_foreign` (`fcv_typefrais_id`),
  KEY `n_fraisconvenu_fcv_typeperiode_id_foreign` (`fcv_typeperiode_id`),
  KEY `n_fraisconvenu_fcv_cree_par_foreign` (`fcv_cree_par`),
  KEY `fcv_plp_id` (`fcv_plp_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_fraisconvenu_fcv_cree_par_foreign` FOREIGN KEY (`fcv_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_fraisconvenu_fcv_ins_id_foreign` FOREIGN KEY (`fcv_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_fraisconvenu_fcv_plp_id_foreign` FOREIGN KEY (`fcv_plp_id`) REFERENCES `n_plans_paiement` (`plp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_fraisconvenu_fcv_typefrais_id_foreign` FOREIGN KEY (`fcv_typefrais_id`) REFERENCES `n_types_frais` (`tpf_id`),
  CONSTRAINT `n_fraisconvenu_fcv_typeperiode_id_foreign` FOREIGN KEY (`fcv_typeperiode_id`) REFERENCES `n_types_periodes_frais` (`tp_id`),
  CONSTRAINT `chk_fcv_montant` CHECK ((`fcv_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_grilles_tarifaires
DROP TABLE IF EXISTS `n_grilles_tarifaires`;
CREATE TABLE `n_grilles_tarifaires` (
  `gt_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `gt_formation_id` bigint unsigned NOT NULL,
  `gt_niveau_filiere` tinyint unsigned DEFAULT NULL,
  `gt_centre_id` bigint unsigned NOT NULL,
  `gt_as_id` bigint unsigned NOT NULL,
  `gt_mode_id` bigint unsigned DEFAULT NULL,
  `gt_typefrais_id` bigint unsigned NOT NULL,
  `gt_typeperiode_id` bigint unsigned NOT NULL,
  `gt_public` enum('tous','marocain','etranger') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'tous',
  `gt_montant_annuel` decimal(12,2) NOT NULL,
  `gt_devise` char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'MAD',
  `gt_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `gt_niveau_key` tinyint unsigned GENERATED ALWAYS AS (ifnull(`gt_niveau_filiere`,0)) STORED,
  `gt_mode_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`gt_mode_id`,0)) STORED,
  PRIMARY KEY (`gt_id`),
  UNIQUE KEY `uq_grille` (`gt_formation_id`,`gt_niveau_key`,`gt_centre_id`,`gt_as_id`,`gt_mode_key`,`gt_typefrais_id`,`gt_public`),
  KEY `n_grilles_tarifaires_gt_centre_id_foreign` (`gt_centre_id`),
  KEY `n_grilles_tarifaires_gt_as_id_foreign` (`gt_as_id`),
  KEY `n_grilles_tarifaires_gt_mode_id_foreign` (`gt_mode_id`),
  KEY `n_grilles_tarifaires_gt_typefrais_id_foreign` (`gt_typefrais_id`),
  KEY `n_grilles_tarifaires_gt_typeperiode_id_foreign` (`gt_typeperiode_id`),
  KEY `fk_gt_formation_centre` (`gt_formation_id`,`gt_centre_id`),
  KEY `n_grilles_tarifaires_created_by_foreign` (`created_by`),
  KEY `n_grilles_tarifaires_updated_by_foreign` (`updated_by`),
  CONSTRAINT `fk_gt_formation_centre` FOREIGN KEY (`gt_formation_id`, `gt_centre_id`) REFERENCES `n_formations` (`for_id`, `for_centre_id`),
  CONSTRAINT `n_grilles_tarifaires_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_grilles_tarifaires_gt_as_id_foreign` FOREIGN KEY (`gt_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_grilles_tarifaires_gt_centre_id_foreign` FOREIGN KEY (`gt_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_grilles_tarifaires_gt_mode_id_foreign` FOREIGN KEY (`gt_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_grilles_tarifaires_gt_typefrais_id_foreign` FOREIGN KEY (`gt_typefrais_id`) REFERENCES `n_types_frais` (`tpf_id`),
  CONSTRAINT `n_grilles_tarifaires_gt_typeperiode_id_foreign` FOREIGN KEY (`gt_typeperiode_id`) REFERENCES `n_types_periodes_frais` (`tp_id`),
  CONSTRAINT `n_grilles_tarifaires_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_gt_montant` CHECK ((`gt_montant_annuel` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_groupecritere_lignes
DROP TABLE IF EXISTS `n_groupecritere_lignes`;
CREATE TABLE `n_groupecritere_lignes` (
  `gcl_gc_id` bigint unsigned NOT NULL,
  `gcl_ca_id` bigint unsigned NOT NULL,
  `gcl_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `gcl_est_obligatoire` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`gcl_gc_id`,`gcl_ca_id`),
  KEY `n_groupecritere_lignes_gcl_ca_id_foreign` (`gcl_ca_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_groupecritere_lignes_gcl_ca_id_foreign` FOREIGN KEY (`gcl_ca_id`) REFERENCES `n_criteres_access` (`ca_id`) ON DELETE CASCADE,
  CONSTRAINT `n_groupecritere_lignes_gcl_gc_id_foreign` FOREIGN KEY (`gcl_gc_id`) REFERENCES `n_groupes_criteres` (`gc_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_groupement_diplomes
DROP TABLE IF EXISTS `n_groupement_diplomes`;
CREATE TABLE `n_groupement_diplomes` (
  `gd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `gd_abbr` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `gd_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `gd_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `gd_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`gd_id`),
  UNIQUE KEY `n_groupement_diplomes_gd_abbr_unique` (`gd_abbr`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_groupes
DROP TABLE IF EXISTS `n_groupes`;
CREATE TABLE `n_groupes` (
  `grp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `grp_nom` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `grp_period` enum('jour','soir') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `grp_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `grp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`grp_id`),
  UNIQUE KEY `n_groupes_grp_nom_unique` (`grp_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_groupes_criteres
DROP TABLE IF EXISTS `n_groupes_criteres`;
CREATE TABLE `n_groupes_criteres` (
  `gc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `gc_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `gc_classe_id` bigint unsigned DEFAULT NULL,
  `gc_diplome_id` bigint unsigned DEFAULT NULL,
  `gc_portee` char(1) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'M = Marocain, E = autre nationalité (liste par diplôme)',
  `gc_acces_id` bigint unsigned DEFAULT NULL,
  `gc_nat_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `gc_nat_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`gc_nat_id`,0)) STORED,
  `gc_acces_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`gc_acces_id`,0)) STORED,
  PRIMARY KEY (`gc_id`),
  UNIQUE KEY `uq_gc_classe_nat` (`gc_classe_id`,`gc_nat_key`),
  UNIQUE KEY `uq_gc_diplome_portee_acces` (`gc_diplome_id`,`gc_portee`,`gc_acces_key`),
  KEY `n_groupes_criteres_gc_nat_id_foreign` (`gc_nat_id`),
  KEY `idx_created_by` (`created_by`),
  KEY `n_groupes_criteres_gc_acces_id_foreign` (`gc_acces_id`),
  CONSTRAINT `n_groupes_criteres_gc_acces_id_foreign` FOREIGN KEY (`gc_acces_id`) REFERENCES `n_types_diplomes_acces` (`tda_id`),
  CONSTRAINT `n_groupes_criteres_gc_classe_id_foreign` FOREIGN KEY (`gc_classe_id`) REFERENCES `n_classes` (`classe_id`) ON DELETE CASCADE,
  CONSTRAINT `n_groupes_criteres_gc_diplome_id_foreign` FOREIGN KEY (`gc_diplome_id`) REFERENCES `n_diplomes` (`dip_id`) ON DELETE CASCADE,
  CONSTRAINT `n_groupes_criteres_gc_nat_id_foreign` FOREIGN KEY (`gc_nat_id`) REFERENCES `n_nationalites` (`nat_id`),
  CONSTRAINT `chk_gc_acces` CHECK (((`gc_acces_id` is null) or (`gc_diplome_id` is not null))),
  CONSTRAINT `chk_gc_cible` CHECK ((((`gc_classe_id` is not null) and (`gc_diplome_id` is null) and (`gc_portee` is null)) or ((`gc_classe_id` is null) and (`gc_diplome_id` is not null) and (`gc_portee` is not null)))),
  CONSTRAINT `chk_gc_portee` CHECK (((`gc_portee` is null) or (`gc_portee` in ('M','E'))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_groupes_projets
DROP TABLE IF EXISTS `n_groupes_projets`;
CREATE TABLE `n_groupes_projets` (
  `gp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `gp_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`gp_id`),
  UNIQUE KEY `n_groupes_projets_gp_nom_unique` (`gp_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_historique_disciplinaire
DROP TABLE IF EXISTS `n_historique_disciplinaire`;
CREATE TABLE `n_historique_disciplinaire` (
  `hd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hd_ins_id` bigint unsigned NOT NULL,
  `hd_date` date NOT NULL,
  `hd_evenement` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `hd_description` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `hd_cree_par_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`hd_id`),
  KEY `n_historique_disciplinaire_hd_cree_par_user_id_foreign` (`hd_cree_par_user_id`),
  KEY `n_historique_disciplinaire_hd_ins_id_hd_date_index` (`hd_ins_id`,`hd_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_historique_disciplinaire_hd_cree_par_user_id_foreign` FOREIGN KEY (`hd_cree_par_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_historique_disciplinaire_hd_ins_id_foreign` FOREIGN KEY (`hd_ins_id`) REFERENCES `n_inscriptions` (`ins_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_historique_notes
DROP TABLE IF EXISTS `n_historique_notes`;
CREATE TABLE `n_historique_notes` (
  `hn_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hn_ins_id` bigint unsigned NOT NULL,
  `hn_exam_id` bigint unsigned NOT NULL,
  `hn_avant` decimal(5,2) DEFAULT NULL,
  `hn_apres` decimal(5,2) DEFAULT NULL,
  `hn_absent_avant` tinyint(1) NOT NULL DEFAULT '0',
  `hn_absent_apres` tinyint(1) NOT NULL DEFAULT '0',
  `hn_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `hn_user_id` bigint unsigned DEFAULT NULL,
  `hn_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`hn_id`),
  KEY `n_historique_notes_hn_ins_id_foreign` (`hn_ins_id`),
  KEY `n_historique_notes_hn_user_id_foreign` (`hn_user_id`),
  KEY `n_historique_notes_hn_exam_id_hn_ins_id_index` (`hn_exam_id`,`hn_ins_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_historique_notes_hn_exam_id_foreign` FOREIGN KEY (`hn_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE CASCADE,
  CONSTRAINT `n_historique_notes_hn_ins_id_foreign` FOREIGN KEY (`hn_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_historique_notes_hn_user_id_foreign` FOREIGN KEY (`hn_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_historique_statut
DROP TABLE IF EXISTS `n_historique_statut`;
CREATE TABLE `n_historique_statut` (
  `hs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hs_pre_id` bigint unsigned NOT NULL,
  `hs_statut_id` bigint unsigned NOT NULL,
  `hs_motif_perte_id` bigint unsigned DEFAULT NULL,
  `hs_commentaire` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `hs_user_id` bigint unsigned DEFAULT NULL,
  `hs_date_changement` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`hs_id`),
  KEY `n_historique_statut_hs_statut_id_foreign` (`hs_statut_id`),
  KEY `n_historique_statut_hs_motif_perte_id_foreign` (`hs_motif_perte_id`),
  KEY `n_historique_statut_hs_user_id_foreign` (`hs_user_id`),
  KEY `n_historique_statut_hs_pre_id_hs_date_changement_index` (`hs_pre_id`,`hs_date_changement`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_historique_statut_hs_motif_perte_id_foreign` FOREIGN KEY (`hs_motif_perte_id`) REFERENCES `n_motifs_perte` (`mp_id`),
  CONSTRAINT `n_historique_statut_hs_pre_id_foreign` FOREIGN KEY (`hs_pre_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_historique_statut_hs_statut_id_foreign` FOREIGN KEY (`hs_statut_id`) REFERENCES `n_statuts_prospect` (`stp_id`),
  CONSTRAINT `n_historique_statut_hs_user_id_foreign` FOREIGN KEY (`hs_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_historique_statuts_demande
DROP TABLE IF EXISTS `n_historique_statuts_demande`;
CREATE TABLE `n_historique_statuts_demande` (
  `hsd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hsd_dem_id` bigint unsigned NOT NULL,
  `hsd_de_id` bigint unsigned DEFAULT NULL,
  `hsd_vers_id` bigint unsigned NOT NULL,
  `hsd_motif` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `hsd_user_id` bigint unsigned DEFAULT NULL,
  `hsd_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`hsd_id`),
  KEY `n_historique_statuts_demande_hsd_de_id_foreign` (`hsd_de_id`),
  KEY `n_historique_statuts_demande_hsd_vers_id_foreign` (`hsd_vers_id`),
  KEY `n_historique_statuts_demande_hsd_user_id_foreign` (`hsd_user_id`),
  KEY `n_historique_statuts_demande_hsd_dem_id_hsd_date_index` (`hsd_dem_id`,`hsd_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_historique_statuts_demande_hsd_de_id_foreign` FOREIGN KEY (`hsd_de_id`) REFERENCES `n_statuts_demandes` (`ds_id`),
  CONSTRAINT `n_historique_statuts_demande_hsd_dem_id_foreign` FOREIGN KEY (`hsd_dem_id`) REFERENCES `n_demandes` (`dem_id`) ON DELETE CASCADE,
  CONSTRAINT `n_historique_statuts_demande_hsd_user_id_foreign` FOREIGN KEY (`hsd_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_historique_statuts_demande_hsd_vers_id_foreign` FOREIGN KEY (`hsd_vers_id`) REFERENCES `n_statuts_demandes` (`ds_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_historique_statuts_inscription
DROP TABLE IF EXISTS `n_historique_statuts_inscription`;
CREATE TABLE `n_historique_statuts_inscription` (
  `hsi_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `hsi_ins_id` bigint unsigned NOT NULL,
  `hsi_de_id` bigint unsigned DEFAULT NULL,
  `hsi_vers_id` bigint unsigned NOT NULL,
  `hsi_motif` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `hsi_user_id` bigint unsigned DEFAULT NULL,
  `hsi_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`hsi_id`),
  KEY `n_historique_statuts_inscription_hsi_de_id_foreign` (`hsi_de_id`),
  KEY `n_historique_statuts_inscription_hsi_vers_id_foreign` (`hsi_vers_id`),
  KEY `n_historique_statuts_inscription_hsi_user_id_foreign` (`hsi_user_id`),
  KEY `n_historique_statuts_inscription_hsi_ins_id_hsi_date_index` (`hsi_ins_id`,`hsi_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_historique_statuts_inscription_hsi_de_id_foreign` FOREIGN KEY (`hsi_de_id`) REFERENCES `n_statuts_inscriptions` (`si_id`),
  CONSTRAINT `n_historique_statuts_inscription_hsi_ins_id_foreign` FOREIGN KEY (`hsi_ins_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE,
  CONSTRAINT `n_historique_statuts_inscription_hsi_user_id_foreign` FOREIGN KEY (`hsi_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_historique_statuts_inscription_hsi_vers_id_foreign` FOREIGN KEY (`hsi_vers_id`) REFERENCES `n_statuts_inscriptions` (`si_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_inscription_sequence
DROP TABLE IF EXISTS `n_inscription_sequence`;
CREATE TABLE `n_inscription_sequence` (
  `inseq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inseq_as_id` bigint unsigned NOT NULL,
  `inseq_filiere_id` bigint unsigned NOT NULL,
  `inseq_sequence` int unsigned NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`inseq_id`),
  UNIQUE KEY `uq_inseq_as_filiere` (`inseq_as_id`,`inseq_filiere_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_inscription_sequence_inseq_as_id_foreign` FOREIGN KEY (`inseq_as_id`) REFERENCES `n_annees_scolaires` (`as_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_inscriptions
DROP TABLE IF EXISTS `n_inscriptions`;
CREATE TABLE `n_inscriptions` (
  `ins_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ins_seq` int unsigned NOT NULL,
  `ins_numero` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ins_date` date NOT NULL,
  `ins_adm_id` bigint unsigned NOT NULL,
  `ins_etudiant_id` bigint unsigned NOT NULL,
  `ins_as_id` bigint unsigned NOT NULL,
  `ins_classe_id` bigint unsigned NOT NULL,
  `ins_classe_spec_id` bigint unsigned DEFAULT NULL,
  `ins_grp_id` bigint unsigned DEFAULT NULL,
  `ins_gp_id` bigint unsigned DEFAULT NULL,
  `ins_mode_id` bigint unsigned NOT NULL,
  `ins_site_id` bigint unsigned DEFAULT NULL,
  `ins_statut_id` bigint unsigned NOT NULL,
  `ins_note_est_affichee` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ins_id`),
  UNIQUE KEY `n_inscriptions_ins_adm_id_ins_as_id_unique` (`ins_adm_id`,`ins_as_id`),
  UNIQUE KEY `n_inscriptions_ins_numero_ins_as_id_unique` (`ins_numero`,`ins_as_id`),
  KEY `n_inscriptions_ins_etudiant_id_foreign` (`ins_etudiant_id`),
  KEY `n_inscriptions_ins_classe_id_foreign` (`ins_classe_id`),
  KEY `n_inscriptions_ins_classe_spec_id_foreign` (`ins_classe_spec_id`),
  KEY `n_inscriptions_ins_grp_id_foreign` (`ins_grp_id`),
  KEY `n_inscriptions_ins_mode_id_foreign` (`ins_mode_id`),
  KEY `n_inscriptions_ins_site_id_foreign` (`ins_site_id`),
  KEY `n_inscriptions_ins_statut_id_foreign` (`ins_statut_id`),
  KEY `n_inscriptions_ins_as_id_ins_classe_id_index` (`ins_as_id`,`ins_classe_id`),
  KEY `n_inscriptions_ins_gp_id_foreign` (`ins_gp_id`),
  KEY `n_inscriptions_created_by_foreign` (`created_by`),
  KEY `n_inscriptions_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_inscriptions_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_inscriptions_ins_adm_id_foreign` FOREIGN KEY (`ins_adm_id`) REFERENCES `n_admissions` (`adm_id`),
  CONSTRAINT `n_inscriptions_ins_as_id_foreign` FOREIGN KEY (`ins_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_inscriptions_ins_classe_id_foreign` FOREIGN KEY (`ins_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_inscriptions_ins_classe_spec_id_foreign` FOREIGN KEY (`ins_classe_spec_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_inscriptions_ins_etudiant_id_foreign` FOREIGN KEY (`ins_etudiant_id`) REFERENCES `n_etudiants` (`etud_id`),
  CONSTRAINT `n_inscriptions_ins_gp_id_foreign` FOREIGN KEY (`ins_gp_id`) REFERENCES `n_groupes_projets` (`gp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_inscriptions_ins_grp_id_foreign` FOREIGN KEY (`ins_grp_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_inscriptions_ins_mode_id_foreign` FOREIGN KEY (`ins_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_inscriptions_ins_site_id_foreign` FOREIGN KEY (`ins_site_id`) REFERENCES `n_sites` (`site_id`),
  CONSTRAINT `n_inscriptions_ins_statut_id_foreign` FOREIGN KEY (`ins_statut_id`) REFERENCES `n_statuts_inscriptions` (`si_id`),
  CONSTRAINT `n_inscriptions_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_journal_actions
DROP TABLE IF EXISTS `n_journal_actions`;
CREATE TABLE `n_journal_actions` (
  `ja_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `request_id` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `role` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `espace` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `type` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL,
  `evenement` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cible_table` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cible_id` bigint unsigned DEFAULT NULL,
  `methode` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uri` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `route` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `statut` smallint unsigned DEFAULT NULL,
  `ip` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `duree_ms` int unsigned DEFAULT NULL,
  `cibles` json DEFAULT NULL,
  `payload` json DEFAULT NULL,
  `contexte` json DEFAULT NULL,
  `source` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ja_id`),
  KEY `n_journal_actions_user_id_created_at_index` (`user_id`,`created_at`),
  KEY `n_journal_actions_created_at_index` (`created_at`),
  KEY `n_journal_actions_request_id_index` (`request_id`),
  KEY `n_journal_actions_type_index` (`type`),
  KEY `n_journal_actions_evenement_index` (`evenement`),
  KEY `n_journal_actions_ip_index` (`ip`),
  KEY `n_journal_actions_created_by_index` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_journal_audit
DROP TABLE IF EXISTS `n_journal_audit`;
CREATE TABLE `n_journal_audit` (
  `aud_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `aud_table` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `aud_ligne_id` bigint unsigned NOT NULL,
  `aud_action` enum('creation','modification','suppression','restauration') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `aud_valeurs_avant` json DEFAULT NULL,
  `aud_valeurs_apres` json DEFAULT NULL,
  `aud_user_id` bigint unsigned DEFAULT NULL,
  `aud_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_user_agent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_request_id` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_source` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_contexte` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_niveau` enum('trigger','complet','leger') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `aud_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`aud_id`),
  KEY `n_journal_audit_aud_table_aud_ligne_id_index` (`aud_table`,`aud_ligne_id`),
  KEY `n_journal_audit_aud_user_id_aud_date_index` (`aud_user_id`,`aud_date`),
  KEY `n_journal_audit_aud_request_id_index` (`aud_request_id`),
  KEY `n_journal_audit_aud_date_index` (`aud_date`),
  KEY `n_journal_audit_aud_action_aud_date_index` (`aud_action`,`aud_date`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_journal_connexions
DROP TABLE IF EXISTS `n_journal_connexions`;
CREATE TABLE `n_journal_connexions` (
  `jc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `jc_user_id` bigint unsigned DEFAULT NULL,
  `jc_identifiant` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `jc_est_reussie` tinyint(1) NOT NULL,
  `jc_type` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'connexion',
  `jc_motif_echec` enum('mot_de_passe','compte_inconnu','compte_inactif','bloque','autre') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `jc_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `jc_user_agent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `jc_request_id` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `jc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`jc_id`),
  KEY `n_journal_connexions_jc_user_id_foreign` (`jc_user_id`),
  KEY `n_journal_connexions_jc_identifiant_jc_date_index` (`jc_identifiant`,`jc_date`),
  KEY `n_journal_connexions_jc_ip_jc_date_index` (`jc_ip`,`jc_date`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_jours_feries
DROP TABLE IF EXISTS `n_jours_feries`;
CREATE TABLE `n_jours_feries` (
  `jf_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `jf_nom` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `jf_date_deb` date NOT NULL,
  `jf_date_fin` date NOT NULL,
  `jf_as_id` bigint unsigned NOT NULL,
  `jf_centre_id` bigint unsigned DEFAULT NULL,
  `jf_type_id` bigint unsigned NOT NULL,
  `jf_demi_journee` enum('J','M','AM') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'J',
  `jf_modele_id` bigint unsigned DEFAULT NULL,
  `jf_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`jf_id`),
  UNIQUE KEY `uq_jf` (`jf_as_id`,`jf_centre_id`,`jf_date_deb`,`jf_demi_journee`),
  KEY `n_jours_feries_jf_centre_id_foreign` (`jf_centre_id`),
  KEY `n_jours_feries_jf_type_id_foreign` (`jf_type_id`),
  KEY `n_jours_feries_jf_modele_id_foreign` (`jf_modele_id`),
  KEY `n_jours_feries_jf_cree_par_foreign` (`jf_cree_par`),
  KEY `n_jours_feries_jf_date_deb_jf_date_fin_index` (`jf_date_deb`,`jf_date_fin`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_jours_feries_jf_as_id_foreign` FOREIGN KEY (`jf_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_jours_feries_jf_centre_id_foreign` FOREIGN KEY (`jf_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_jours_feries_jf_cree_par_foreign` FOREIGN KEY (`jf_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_jours_feries_jf_modele_id_foreign` FOREIGN KEY (`jf_modele_id`) REFERENCES `n_jours_feries_modeles` (`jfm_id`) ON DELETE SET NULL,
  CONSTRAINT `n_jours_feries_jf_type_id_foreign` FOREIGN KEY (`jf_type_id`) REFERENCES `n_types_details_calenders` (`dc_id`),
  CONSTRAINT `chk_jf_dates` CHECK ((`jf_date_fin` >= `jf_date_deb`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_jours_feries_modeles
DROP TABLE IF EXISTS `n_jours_feries_modeles`;
CREATE TABLE `n_jours_feries_modeles` (
  `jfm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `jfm_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `jfm_type_id` bigint unsigned NOT NULL,
  `jfm_mois` tinyint unsigned NOT NULL,
  `jfm_jour` tinyint unsigned NOT NULL,
  `jfm_nb_jours` tinyint unsigned NOT NULL DEFAULT '1',
  `jfm_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`jfm_id`),
  UNIQUE KEY `n_jours_feries_modeles_jfm_label_unique` (`jfm_label`),
  KEY `n_jours_feries_modeles_jfm_type_id_foreign` (`jfm_type_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_jours_feries_modeles_jfm_type_id_foreign` FOREIGN KEY (`jfm_type_id`) REFERENCES `n_types_details_calenders` (`dc_id`),
  CONSTRAINT `chk_jfm_jour` CHECK ((`jfm_jour` between 1 and 31)),
  CONSTRAINT `chk_jfm_mois` CHECK ((`jfm_mois` between 1 and 12)),
  CONSTRAINT `chk_jfm_nb_jours` CHECK ((`jfm_nb_jours` between 1 and 31))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_laureats_annuaire
DROP TABLE IF EXISTS `n_laureats_annuaire`;
CREATE TABLE `n_laureats_annuaire` (
  `la_etud_id` bigint unsigned NOT NULL,
  `la_consentement` tinyint(1) NOT NULL DEFAULT '0',
  `la_consenti_le` timestamp NULL DEFAULT NULL,
  `la_email_contact` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `la_linkedin` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`la_etud_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_laureats_annuaire_la_etud_id_foreign` FOREIGN KEY (`la_etud_id`) REFERENCES `n_etudiants` (`etud_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_laureats_situations
DROP TABLE IF EXISTS `n_laureats_situations`;
CREATE TABLE `n_laureats_situations` (
  `lsit_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `lsit_ins_id` bigint unsigned NOT NULL,
  `lsit_etud_id` bigint unsigned NOT NULL,
  `lsit_situation` enum('emploi','poursuite_etudes','recherche','entrepreneuriat','stage','autre') COLLATE utf8mb4_unicode_ci NOT NULL,
  `lsit_ent_id` bigint unsigned DEFAULT NULL,
  `lsit_organisme` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_secteur` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_poste` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_type_contrat` enum('cdi','cdd','anapec','freelance','fonction_publique','stage','autre') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_date_debut` date DEFAULT NULL,
  `lsit_tranche_salaire` enum('moins_5k','5k_8k','8k_12k','12k_20k','plus_20k') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_ville` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_pays` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_source` enum('enquete','declaration','saisie') COLLATE utf8mb4_unicode_ci NOT NULL,
  `lsit_date_info` date NOT NULL,
  `lsit_enq_id` bigint unsigned DEFAULT NULL,
  `lsit_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `lsit_saisi_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`lsit_id`),
  KEY `n_laureats_situations_lsit_ent_id_foreign` (`lsit_ent_id`),
  KEY `n_laureats_situations_lsit_enq_id_foreign` (`lsit_enq_id`),
  KEY `n_laureats_situations_lsit_saisi_par_foreign` (`lsit_saisi_par`),
  KEY `n_laureats_situations_lsit_ins_id_lsit_date_info_index` (`lsit_ins_id`,`lsit_date_info`),
  KEY `n_laureats_situations_lsit_etud_id_index` (`lsit_etud_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_laureats_situations_lsit_enq_id_foreign` FOREIGN KEY (`lsit_enq_id`) REFERENCES `n_enquetes_insertion` (`enq_id`) ON DELETE SET NULL,
  CONSTRAINT `n_laureats_situations_lsit_ent_id_foreign` FOREIGN KEY (`lsit_ent_id`) REFERENCES `n_entreprises` (`ent_id`) ON DELETE SET NULL,
  CONSTRAINT `n_laureats_situations_lsit_etud_id_foreign` FOREIGN KEY (`lsit_etud_id`) REFERENCES `n_etudiants` (`etud_id`),
  CONSTRAINT `n_laureats_situations_lsit_ins_id_foreign` FOREIGN KEY (`lsit_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_laureats_situations_lsit_saisi_par_foreign` FOREIGN KEY (`lsit_saisi_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_liens_parente
DROP TABLE IF EXISTS `n_liens_parente`;
CREATE TABLE `n_liens_parente` (
  `lp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `lp_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `lp_libelle` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `lp_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `lp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`lp_id`),
  UNIQUE KEY `n_liens_parente_lp_code_unique` (`lp_code`),
  UNIQUE KEY `n_liens_parente_lp_libelle_unique` (`lp_libelle`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_lignes_operation
DROP TABLE IF EXISTS `n_lignes_operation`;
CREATE TABLE `n_lignes_operation` (
  `lop_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `lop_op_id` bigint unsigned NOT NULL,
  `lop_cs_id` bigint unsigned NOT NULL,
  `lop_mp_id` bigint unsigned NOT NULL,
  `lop_montant` decimal(12,2) NOT NULL,
  `lop_piece_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`lop_id`),
  KEY `n_lignes_operation_lop_op_id_foreign` (`lop_op_id`),
  KEY `n_lignes_operation_lop_cs_id_foreign` (`lop_cs_id`),
  KEY `n_lignes_operation_lop_mp_id_foreign` (`lop_mp_id`),
  KEY `n_lignes_operation_lop_piece_id_foreign` (`lop_piece_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_lignes_operation_lop_cs_id_foreign` FOREIGN KEY (`lop_cs_id`) REFERENCES `n_comptes_societe` (`cs_id`),
  CONSTRAINT `n_lignes_operation_lop_mp_id_foreign` FOREIGN KEY (`lop_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`),
  CONSTRAINT `n_lignes_operation_lop_op_id_foreign` FOREIGN KEY (`lop_op_id`) REFERENCES `n_operations` (`op_id`) ON DELETE CASCADE,
  CONSTRAINT `n_lignes_operation_lop_piece_id_foreign` FOREIGN KEY (`lop_piece_id`) REFERENCES `n_pieces` (`pc_id`),
  CONSTRAINT `chk_lop_montant` CHECK ((`lop_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_listes_absences
DROP TABLE IF EXISTS `n_listes_absences`;
CREATE TABLE `n_listes_absences` (
  `abs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `abs_exam_id` bigint unsigned NOT NULL,
  `abs_fichier_id` bigint unsigned DEFAULT NULL,
  `abs_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`abs_id`),
  KEY `n_listes_absences_abs_exam_id_foreign` (`abs_exam_id`),
  KEY `n_listes_absences_abs_fichier_id_foreign` (`abs_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_listes_absences_abs_exam_id_foreign` FOREIGN KEY (`abs_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE CASCADE,
  CONSTRAINT `n_listes_absences_abs_fichier_id_foreign` FOREIGN KEY (`abs_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_listes_laureats
DROP TABLE IF EXISTS `n_listes_laureats`;
CREATE TABLE `n_listes_laureats` (
  `liste_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `liste_as_id` bigint unsigned NOT NULL,
  `liste_classe_id` bigint unsigned NOT NULL,
  `liste_statut` enum('brouillon','figee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'brouillon',
  `liste_contenu` json DEFAULT NULL,
  `liste_nb` smallint unsigned NOT NULL DEFAULT '0',
  `liste_fichier_id` bigint unsigned DEFAULT NULL,
  `liste_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `liste_generee_le` timestamp NULL DEFAULT NULL,
  `liste_generee_par` bigint unsigned DEFAULT NULL,
  `liste_figee_le` timestamp NULL DEFAULT NULL,
  `liste_figee_par` bigint unsigned DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`liste_id`),
  UNIQUE KEY `n_listes_laureats_liste_as_id_liste_classe_id_unique` (`liste_as_id`,`liste_classe_id`),
  KEY `n_listes_laureats_liste_classe_id_foreign` (`liste_classe_id`),
  KEY `n_listes_laureats_liste_fichier_id_foreign` (`liste_fichier_id`),
  KEY `n_listes_laureats_liste_generee_par_foreign` (`liste_generee_par`),
  KEY `n_listes_laureats_liste_figee_par_foreign` (`liste_figee_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_listes_laureats_liste_as_id_foreign` FOREIGN KEY (`liste_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_listes_laureats_liste_classe_id_foreign` FOREIGN KEY (`liste_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_listes_laureats_liste_fichier_id_foreign` FOREIGN KEY (`liste_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_listes_laureats_liste_figee_par_foreign` FOREIGN KEY (`liste_figee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_listes_laureats_liste_generee_par_foreign` FOREIGN KEY (`liste_generee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_localites
DROP TABLE IF EXISTS `n_localites`;
CREATE TABLE `n_localites` (
  `loc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `loc_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `loc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`loc_id`),
  UNIQUE KEY `n_localites_loc_nom_unique` (`loc_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_logos
DROP TABLE IF EXISTS `n_logos`;
CREATE TABLE `n_logos` (
  `lg_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `lg_centre_id` bigint unsigned DEFAULT NULL,
  `lg_type` enum('principal','principal_sombre','icone','entete_document','pied_document','cachet','filigrane') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `lg_fichier_id` bigint unsigned NOT NULL,
  `lg_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `lg_centre_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`lg_centre_id`,0)) VIRTUAL,
  PRIMARY KEY (`lg_id`),
  UNIQUE KEY `uq_logo` (`lg_centre_key`,`lg_type`),
  KEY `n_logos_lg_centre_id_foreign` (`lg_centre_id`),
  KEY `n_logos_lg_fichier_id_foreign` (`lg_fichier_id`),
  KEY `n_logos_created_by_foreign` (`created_by`),
  CONSTRAINT `n_logos_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_logos_lg_centre_id_foreign` FOREIGN KEY (`lg_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_logos_lg_fichier_id_foreign` FOREIGN KEY (`lg_fichier_id`) REFERENCES `n_fichiers` (`fic_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_mails_echecs
DROP TABLE IF EXISTS `n_mails_echecs`;
CREATE TABLE `n_mails_echecs` (
  `mef_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mef_destinataire` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `mef_type` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `mef_notification` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mef_contexte` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mef_cible_table` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mef_cible_id` bigint unsigned DEFAULT NULL,
  `mef_params` json DEFAULT NULL,
  `mef_user_id` bigint unsigned DEFAULT NULL,
  `mef_code` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'autre',
  `mef_erreur` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
  `mef_erreur_technique` text COLLATE utf8mb4_unicode_ci,
  `mef_tentatives` smallint unsigned NOT NULL DEFAULT '1',
  `mef_statut` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'en_attente',
  `mef_resolu_le` timestamp NULL DEFAULT NULL,
  `mef_resolu_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mef_id`),
  KEY `n_mails_echecs_mef_cible_table_mef_cible_id_index` (`mef_cible_table`,`mef_cible_id`),
  KEY `n_mails_echecs_mef_destinataire_index` (`mef_destinataire`),
  KEY `n_mails_echecs_mef_type_index` (`mef_type`),
  KEY `n_mails_echecs_mef_statut_index` (`mef_statut`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_matieres
DROP TABLE IF EXISTS `n_matieres`;
CREATE TABLE `n_matieres` (
  `mat_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mat_abbr` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mat_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mat_centre_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mat_id`),
  KEY `n_matieres_mat_centre_id_mat_nom_index` (`mat_centre_id`,`mat_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_matieres_mat_centre_id_foreign` FOREIGN KEY (`mat_centre_id`) REFERENCES `n_centres` (`ct_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_membres_jury
DROP TABLE IF EXISTS `n_membres_jury`;
CREATE TABLE `n_membres_jury` (
  `mj_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mj_role` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `mj_responsable` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
  `mj_centre_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mj_id`),
  KEY `n_membres_jury_mj_centre_id_foreign` (`mj_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_membres_jury_mj_centre_id_foreign` FOREIGN KEY (`mj_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_mentions
DROP TABLE IF EXISTS `n_mentions`;
CREATE TABLE `n_mentions` (
  `men_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `men_code` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `men_libelle` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `men_ordre` tinyint unsigned NOT NULL,
  `men_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`men_id`),
  UNIQUE KEY `n_mentions_men_code_unique` (`men_code`),
  UNIQUE KEY `n_mentions_men_libelle_unique` (`men_libelle`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_message_fichiers
DROP TABLE IF EXISTS `n_message_fichiers`;
CREATE TABLE `n_message_fichiers` (
  `mf_msg_id` bigint unsigned NOT NULL,
  `mf_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mf_msg_id`,`mf_fichier_id`),
  KEY `n_message_fichiers_mf_fichier_id_foreign` (`mf_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_message_fichiers_mf_fichier_id_foreign` FOREIGN KEY (`mf_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_message_fichiers_mf_msg_id_foreign` FOREIGN KEY (`mf_msg_id`) REFERENCES `n_messages` (`msg_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_messages
DROP TABLE IF EXISTS `n_messages`;
CREATE TABLE `n_messages` (
  `msg_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `msg_conv_id` bigint unsigned NOT NULL,
  `msg_auteur_id` bigint unsigned NOT NULL,
  `msg_contenu` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `msg_supprime_le` timestamp NULL DEFAULT NULL,
  `msg_signale_le` timestamp NULL DEFAULT NULL,
  `msg_signale_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`msg_id`),
  KEY `n_messages_msg_auteur_id_foreign` (`msg_auteur_id`),
  KEY `n_messages_msg_signale_par_foreign` (`msg_signale_par`),
  KEY `n_messages_msg_conv_id_msg_id_index` (`msg_conv_id`,`msg_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_messages_msg_auteur_id_foreign` FOREIGN KEY (`msg_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_messages_msg_conv_id_foreign` FOREIGN KEY (`msg_conv_id`) REFERENCES `n_conversations` (`conv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_messages_msg_signale_par_foreign` FOREIGN KEY (`msg_signale_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_mises_a_niveau
DROP TABLE IF EXISTS `n_mises_a_niveau`;
CREATE TABLE `n_mises_a_niveau` (
  `man_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `man_adm_id` bigint unsigned NOT NULL,
  `man_module_libelle` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `man_duree_heures` smallint unsigned DEFAULT NULL,
  `man_appreciation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`man_id`),
  UNIQUE KEY `n_mises_a_niveau_man_adm_id_man_module_libelle_unique` (`man_adm_id`,`man_module_libelle`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_mises_a_niveau_man_adm_id_foreign` FOREIGN KEY (`man_adm_id`) REFERENCES `n_admissions` (`adm_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modeles_diplomes
DROP TABLE IF EXISTS `n_modeles_diplomes`;
CREATE TABLE `n_modeles_diplomes` (
  `mol_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mol_filiere_id` bigint unsigned NOT NULL,
  `mol_centre_id` bigint unsigned NOT NULL,
  `mol_nationalite` enum('M','E') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mol_libelle` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mol_contenu` mediumtext COLLATE utf8mb4_unicode_ci,
  `mol_orientation` enum('paysage','portrait') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'paysage',
  `mol_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `mol_fichier_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mol_id`),
  UNIQUE KEY `uq_modeles_diplomes_filier_centre_nation` (`mol_filiere_id`,`mol_centre_id`,`mol_nationalite`),
  KEY `n_modeles_diplomes_mol_centre_id_foreign` (`mol_centre_id`),
  KEY `n_modeles_diplomes_mol_fichier_id_foreign` (`mol_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_modeles_diplomes_mol_centre_id_foreign` FOREIGN KEY (`mol_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_modeles_diplomes_mol_fichier_id_foreign` FOREIGN KEY (`mol_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_modeles_diplomes_mol_filiere_id_foreign` FOREIGN KEY (`mol_filiere_id`) REFERENCES `n_filieres` (`fil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modeles_documents
DROP TABLE IF EXISTS `n_modeles_documents`;
CREATE TABLE `n_modeles_documents` (
  `mdoc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mdoc_centre_id` bigint unsigned NOT NULL,
  `mdoc_code` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mdoc_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mdoc_contenu` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mdoc_typedoc_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mdoc_id`),
  UNIQUE KEY `uq_mdoc_centre_nom` (`mdoc_centre_id`,`mdoc_nom`),
  UNIQUE KEY `uq_mdoc_centre_code` (`mdoc_centre_id`,`mdoc_code`),
  KEY `n_modeles_documents_mdoc_typedoc_id_foreign` (`mdoc_typedoc_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_modeles_documents_mdoc_centre_id_foreign` FOREIGN KEY (`mdoc_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_modeles_documents_mdoc_typedoc_id_foreign` FOREIGN KEY (`mdoc_typedoc_id`) REFERENCES `n_types_documents` (`tdoc_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modeles_messages
DROP TABLE IF EXISTS `n_modeles_messages`;
CREATE TABLE `n_modeles_messages` (
  `mm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mm_code` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mm_libelle` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mm_canal` enum('application','email','sms','whatsapp') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mm_langue` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
  `mm_sujet` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mm_contenu` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mm_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mm_id`),
  UNIQUE KEY `uq_modele_message` (`mm_code`,`mm_canal`,`mm_langue`),
  UNIQUE KEY `n_modeles_messages_mm_code_unique` (`mm_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modes_enseignement
DROP TABLE IF EXISTS `n_modes_enseignement`;
CREATE TABLE `n_modes_enseignement` (
  `mode_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mode_code` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mode_libelle` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mode_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `mode_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mode_id`),
  UNIQUE KEY `n_modes_enseignement_mode_code_unique` (`mode_code`),
  UNIQUE KEY `n_modes_enseignement_mode_libelle_unique` (`mode_libelle`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modes_paiement
DROP TABLE IF EXISTS `n_modes_paiement`;
CREATE TABLE `n_modes_paiement` (
  `mp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mp_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mp_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mp_est_piece_requise` tinyint(1) NOT NULL DEFAULT '0',
  `mp_est_a_valider` tinyint(1) NOT NULL DEFAULT '0',
  `mp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `mp_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mp_id`),
  UNIQUE KEY `n_modes_paiement_mp_code_unique` (`mp_code`),
  UNIQUE KEY `n_modes_paiement_mp_nom_unique` (`mp_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `chk_mp_valider` CHECK (((`mp_est_a_valider` = 0) or (`mp_est_piece_requise` = 1)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_modules
DROP TABLE IF EXISTS `n_modules`;
CREATE TABLE `n_modules` (
  `mod_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mod_abbr` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mod_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mod_coordinateur_id` bigint unsigned DEFAULT NULL,
  `mod_centre_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mod_id`),
  KEY `n_modules_mod_coordinateur_id_foreign` (`mod_coordinateur_id`),
  KEY `n_modules_mod_centre_id_mod_nom_index` (`mod_centre_id`,`mod_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_modules_mod_centre_id_foreign` FOREIGN KEY (`mod_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_modules_mod_coordinateur_id_foreign` FOREIGN KEY (`mod_coordinateur_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_motifs_perte
DROP TABLE IF EXISTS `n_motifs_perte`;
CREATE TABLE `n_motifs_perte` (
  `mp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `mp_libelle` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `mp_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `mp_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`mp_id`),
  UNIQUE KEY `n_motifs_perte_mp_libelle_unique` (`mp_libelle`),
  UNIQUE KEY `n_motifs_perte_mp_code_unique` (`mp_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_nationalites
DROP TABLE IF EXISTS `n_nationalites`;
CREATE TABLE `n_nationalites` (
  `nat_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `nat_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `nat_pays_id` bigint unsigned DEFAULT NULL,
  `nat_est_arabe` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`nat_id`),
  UNIQUE KEY `n_nationalites_nat_nom_unique` (`nat_nom`),
  KEY `n_nationalites_nat_pays_id_foreign` (`nat_pays_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_nationalites_nat_pays_id_foreign` FOREIGN KEY (`nat_pays_id`) REFERENCES `n_pays` (`pays_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_niveaux
DROP TABLE IF EXISTS `n_niveaux`;
CREATE TABLE `n_niveaux` (
  `niv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `niv_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `niv_numero` tinyint unsigned NOT NULL,
  `niv_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`niv_id`),
  UNIQUE KEY `n_niveaux_niv_nom_unique` (`niv_nom`),
  UNIQUE KEY `n_niveaux_niv_numero_unique` (`niv_numero`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_notifications
DROP TABLE IF EXISTS `n_notifications`;
CREATE TABLE `n_notifications` (
  `notif_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `notif_user_id` bigint unsigned NOT NULL,
  `notif_modele_id` bigint unsigned DEFAULT NULL,
  `notif_type` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notif_canal` enum('application','email','sms','whatsapp') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `notif_titre` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `notif_contenu` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `notif_lien` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notif_statut` enum('en_attente','envoyee','echec') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'en_attente',
  `notif_erreur` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notif_envoyee_le` timestamp NULL DEFAULT NULL,
  `notif_lue_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`notif_id`),
  KEY `n_notifications_notif_modele_id_foreign` (`notif_modele_id`),
  KEY `n_notifications_notif_user_id_notif_lue_le_index` (`notif_user_id`,`notif_lue_le`),
  KEY `n_notifications_notif_statut_created_at_index` (`notif_statut`,`created_at`),
  KEY `n_notifications_notif_user_id_created_at_index` (`notif_user_id`,`created_at`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_notifications_notif_modele_id_foreign` FOREIGN KEY (`notif_modele_id`) REFERENCES `n_modeles_messages` (`mm_id`) ON DELETE SET NULL,
  CONSTRAINT `n_notifications_notif_user_id_foreign` FOREIGN KEY (`notif_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_nsti_critere_notes
DROP TABLE IF EXISTS `n_nsti_critere_notes`;
CREATE TABLE `n_nsti_critere_notes` (
  `nsti_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `nsti_ins_id` bigint unsigned NOT NULL,
  `nsti_crt_id` bigint unsigned NOT NULL,
  `nsti_crt_note` decimal(20,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`nsti_id`),
  UNIQUE KEY `uq_nsti_student` (`nsti_ins_id`,`nsti_crt_id`),
  KEY `n_nsti_critere_notes_nsti_crt_id_foreign` (`nsti_crt_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_nsti_critere_notes_nsti_crt_id_foreign` FOREIGN KEY (`nsti_crt_id`) REFERENCES `n_nsti_criteres` (`nsti_crt_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `n_nsti_critere_notes_nsti_ins_id_foreign` FOREIGN KEY (`nsti_ins_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_nsti_criteres
DROP TABLE IF EXISTS `n_nsti_criteres`;
CREATE TABLE `n_nsti_criteres` (
  `nsti_crt_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `nsti_crt_nom` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `nsti_crt_coef` decimal(20,6) NOT NULL DEFAULT '0.000000',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`nsti_crt_id`),
  UNIQUE KEY `n_nsti_criteres_nsti_crt_nom_unique` (`nsti_crt_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_num_diplomes
DROP TABLE IF EXISTS `n_num_diplomes`;
CREATE TABLE `n_num_diplomes` (
  `num_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `num_centre_id` bigint unsigned NOT NULL,
  `num_as_id` bigint unsigned NOT NULL,
  `num_dernier_numero` int unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`num_id`),
  UNIQUE KEY `n_num_diplomes_num_centre_id_num_as_id_unique` (`num_centre_id`,`num_as_id`),
  KEY `n_num_diplomes_num_as_id_foreign` (`num_as_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_num_diplomes_num_as_id_foreign` FOREIGN KEY (`num_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_num_diplomes_num_centre_id_foreign` FOREIGN KEY (`num_centre_id`) REFERENCES `n_centres` (`ct_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_objectifs_programme
DROP TABLE IF EXISTS `n_objectifs_programme`;
CREATE TABLE `n_objectifs_programme` (
  `obj_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `obj_emo_id` bigint unsigned NOT NULL,
  `obj_seq_id` bigint unsigned DEFAULT NULL,
  `obj_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `obj_titre` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
  `obj_description` text COLLATE utf8mb4_unicode_ci,
  `obj_type` enum('CM','TD','TP') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `obj_duree` decimal(5,2) DEFAULT NULL,
  `obj_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`obj_id`),
  KEY `n_objectifs_programme_obj_emo_id_foreign` (`obj_emo_id`),
  KEY `n_objectifs_programme_obj_seq_id_foreign` (`obj_seq_id`),
  KEY `n_objectifs_programme_created_by_index` (`created_by`),
  CONSTRAINT `n_objectifs_programme_obj_emo_id_foreign` FOREIGN KEY (`obj_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_objectifs_programme_obj_seq_id_foreign` FOREIGN KEY (`obj_seq_id`) REFERENCES `n_sequences_pedagogiques` (`seq_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_offres_stage
DROP TABLE IF EXISTS `n_offres_stage`;
CREATE TABLE `n_offres_stage` (
  `off_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `off_ent_id` bigint unsigned NOT NULL,
  `off_contact_id` bigint unsigned DEFAULT NULL,
  `off_centre_id` bigint unsigned DEFAULT NULL,
  `off_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `off_description` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `off_type` enum('initiation','technique','pfa','pfe','autre') COLLATE utf8mb4_unicode_ci NOT NULL,
  `off_lieu` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `off_duree_semaines` smallint unsigned DEFAULT NULL,
  `off_date_debut` date DEFAULT NULL,
  `off_nb_postes` smallint unsigned NOT NULL DEFAULT '1',
  `off_date_limite` date DEFAULT NULL,
  `off_formations` json DEFAULT NULL,
  `off_niveaux` json DEFAULT NULL,
  `off_statut` enum('brouillon','publiee','cloturee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'brouillon',
  `off_publiee_le` timestamp NULL DEFAULT NULL,
  `off_auteur_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`off_id`),
  KEY `n_offres_stage_off_ent_id_foreign` (`off_ent_id`),
  KEY `n_offres_stage_off_contact_id_foreign` (`off_contact_id`),
  KEY `n_offres_stage_off_centre_id_foreign` (`off_centre_id`),
  KEY `n_offres_stage_off_auteur_id_foreign` (`off_auteur_id`),
  KEY `n_offres_stage_off_statut_off_date_limite_index` (`off_statut`,`off_date_limite`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_offres_stage_off_auteur_id_foreign` FOREIGN KEY (`off_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_offres_stage_off_centre_id_foreign` FOREIGN KEY (`off_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_offres_stage_off_contact_id_foreign` FOREIGN KEY (`off_contact_id`) REFERENCES `n_entreprise_contacts` (`ec_id`) ON DELETE SET NULL,
  CONSTRAINT `n_offres_stage_off_ent_id_foreign` FOREIGN KEY (`off_ent_id`) REFERENCES `n_entreprises` (`ent_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_operations
DROP TABLE IF EXISTS `n_operations`;
CREATE TABLE `n_operations` (
  `op_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `op_date` date NOT NULL,
  `op_type` enum('recette','depense') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `op_montant` decimal(12,2) NOT NULL,
  `op_libelle` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `op_rb_id` bigint unsigned DEFAULT NULL,
  `op_caisse_id` bigint unsigned DEFAULT NULL,
  `op_recu_id` bigint unsigned DEFAULT NULL,
  `op_numero_facture` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `op_statut` enum('validee','annulee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'validee',
  `op_user_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`op_id`),
  KEY `n_operations_op_rb_id_foreign` (`op_rb_id`),
  KEY `n_operations_op_caisse_id_foreign` (`op_caisse_id`),
  KEY `n_operations_op_recu_id_foreign` (`op_recu_id`),
  KEY `n_operations_op_user_id_foreign` (`op_user_id`),
  KEY `n_operations_op_type_op_date_index` (`op_type`,`op_date`),
  KEY `n_operations_op_numero_facture_index` (`op_numero_facture`),
  KEY `n_operations_created_by_foreign` (`created_by`),
  KEY `n_operations_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_operations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_operations_op_caisse_id_foreign` FOREIGN KEY (`op_caisse_id`) REFERENCES `n_caisse` (`caisse_id`),
  CONSTRAINT `n_operations_op_rb_id_foreign` FOREIGN KEY (`op_rb_id`) REFERENCES `n_rubriques_budgetaires` (`rb_id`),
  CONSTRAINT `n_operations_op_recu_id_foreign` FOREIGN KEY (`op_recu_id`) REFERENCES `n_recus` (`rec_id`) ON DELETE SET NULL,
  CONSTRAINT `n_operations_op_user_id_foreign` FOREIGN KEY (`op_user_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_operations_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_op_montant` CHECK ((`op_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_options
DROP TABLE IF EXISTS `n_options`;
CREATE TABLE `n_options` (
  `opt_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `opt_filiere_id` bigint unsigned NOT NULL,
  `opt_abbr` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `opt_nom` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `opt_nom_ar` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`opt_id`),
  UNIQUE KEY `n_options_opt_filiere_id_opt_abbr_unique` (`opt_filiere_id`,`opt_abbr`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_options_opt_filiere_id_foreign` FOREIGN KEY (`opt_filiere_id`) REFERENCES `n_filieres` (`fil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_parametres
DROP TABLE IF EXISTS `n_parametres`;
CREATE TABLE `n_parametres` (
  `param_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `param_cle` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `param_valeur` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `param_type` enum('string','int','bool','decimal','date','json') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'string',
  `param_description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `param_est_modifiable` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`param_id`),
  UNIQUE KEY `n_parametres_param_cle_unique` (`param_cle`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_parametres_centres
DROP TABLE IF EXISTS `n_parametres_centres`;
CREATE TABLE `n_parametres_centres` (
  `pce_param_id` bigint unsigned NOT NULL,
  `pce_centre_id` bigint unsigned NOT NULL,
  `pce_valeur` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pce_param_id`,`pce_centre_id`),
  KEY `n_parametres_centres_pce_centre_id_foreign` (`pce_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_parametres_centres_pce_centre_id_foreign` FOREIGN KEY (`pce_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_parametres_centres_pce_param_id_foreign` FOREIGN KEY (`pce_param_id`) REFERENCES `n_parametres` (`param_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_parents_resultats_notifies
DROP TABLE IF EXISTS `n_parents_resultats_notifies`;
CREATE TABLE `n_parents_resultats_notifies` (
  `prn_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `prn_del_id` bigint unsigned NOT NULL,
  `prn_nb_parents` int unsigned NOT NULL DEFAULT '0',
  `prn_notifie_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`prn_id`),
  UNIQUE KEY `uq_prn_deliberation` (`prn_del_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_parents_resultats_notifies_prn_del_id_foreign` FOREIGN KEY (`prn_del_id`) REFERENCES `n_deliberations` (`del_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_parents_resumes_absences
DROP TABLE IF EXISTS `n_parents_resumes_absences`;
CREATE TABLE `n_parents_resumes_absences` (
  `pra_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pra_tut_id` bigint unsigned NOT NULL,
  `pra_date` date NOT NULL,
  `pra_nb_absences` smallint unsigned NOT NULL DEFAULT '0',
  `pra_nb_retards` smallint unsigned NOT NULL DEFAULT '0',
  `pra_envoye_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pra_id`),
  UNIQUE KEY `uq_pra_tuteur_date` (`pra_tut_id`,`pra_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_parents_resumes_absences_pra_tut_id_foreign` FOREIGN KEY (`pra_tut_id`) REFERENCES `n_tuteurs` (`tut_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_partenaires
DROP TABLE IF EXISTS `n_partenaires`;
CREATE TABLE `n_partenaires` (
  `par_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `par_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `par_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `par_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `par_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `par_zone` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `par_point_focal` varchar(70) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `par_user_id` bigint unsigned DEFAULT NULL,
  `par_id_externe` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`par_id`),
  UNIQUE KEY `n_partenaires_par_code_unique` (`par_code`),
  UNIQUE KEY `n_partenaires_par_user_id_unique` (`par_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_partenaires_par_user_id_foreign` FOREIGN KEY (`par_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pays
DROP TABLE IF EXISTS `n_pays`;
CREATE TABLE `n_pays` (
  `pays_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pays_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pays_nom_ar` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pays_code_iso2` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pays_code_iso3` char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pays_est_privilegie` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pays_id`),
  UNIQUE KEY `n_pays_pays_nom_unique` (`pays_nom`),
  UNIQUE KEY `n_pays_pays_code_iso2_unique` (`pays_code_iso2`),
  UNIQUE KEY `n_pays_pays_code_iso3_unique` (`pays_code_iso3`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_periodes_convenues
DROP TABLE IF EXISTS `n_periodes_convenues`;
CREATE TABLE `n_periodes_convenues` (
  `pcv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pcv_fcv_id` bigint unsigned NOT NULL,
  `pcv_periode_id` bigint unsigned DEFAULT NULL,
  `pcv_montant` decimal(12,2) NOT NULL,
  `pcv_date_echeance` date DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `pcv_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `pcv_libelle` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pcv_id`),
  UNIQUE KEY `n_periodes_convenues_pcv_fcv_id_pcv_periode_id_unique` (`pcv_fcv_id`,`pcv_periode_id`),
  KEY `n_periodes_convenues_pcv_periode_id_foreign` (`pcv_periode_id`),
  KEY `pcv_date_echeance` (`pcv_date_echeance`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_periodes_convenues_pcv_fcv_id_foreign` FOREIGN KEY (`pcv_fcv_id`) REFERENCES `n_fraisconvenu` (`fcv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_periodes_convenues_pcv_periode_id_foreign` FOREIGN KEY (`pcv_periode_id`) REFERENCES `n_periodes_frais` (`periode_id`),
  CONSTRAINT `chk_pcv_montant` CHECK ((`pcv_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_periodes_frais
DROP TABLE IF EXISTS `n_periodes_frais`;
CREATE TABLE `n_periodes_frais` (
  `periode_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `periode_tp_id` bigint unsigned NOT NULL,
  `periode_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `periode_abbr` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `periode_ordre` tinyint unsigned NOT NULL,
  `periode_mois_echeance` tinyint unsigned DEFAULT NULL,
  `periode_est_visible` tinyint(1) NOT NULL DEFAULT '1',
  `periode_jour_echeance` tinyint unsigned NOT NULL DEFAULT '5',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`periode_id`),
  UNIQUE KEY `n_periodes_frais_periode_tp_id_periode_ordre_unique` (`periode_tp_id`,`periode_ordre`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_periodes_frais_periode_tp_id_foreign` FOREIGN KEY (`periode_tp_id`) REFERENCES `n_types_periodes_frais` (`tp_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_periode_jour` CHECK ((`periode_jour_echeance` between 1 and 28)),
  CONSTRAINT `chk_periode_mois` CHECK (((`periode_mois_echeance` is null) or (`periode_mois_echeance` between 1 and 12)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_periodes_payees
DROP TABLE IF EXISTS `n_periodes_payees`;
CREATE TABLE `n_periodes_payees` (
  `pp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pp_pcv_id` bigint unsigned NOT NULL,
  `pp_recu_id` bigint unsigned NOT NULL,
  `pp_montant` decimal(12,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pp_id`),
  UNIQUE KEY `n_periodes_payees_pp_pcv_id_pp_recu_id_unique` (`pp_pcv_id`,`pp_recu_id`),
  KEY `n_periodes_payees_pp_recu_id_index` (`pp_recu_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_periodes_payees_pp_pcv_id_foreign` FOREIGN KEY (`pp_pcv_id`) REFERENCES `n_periodes_convenues` (`pcv_id`),
  CONSTRAINT `n_periodes_payees_pp_recu_id_foreign` FOREIGN KEY (`pp_recu_id`) REFERENCES `n_recus` (`rec_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_pp_montant` CHECK ((`pp_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_periodes_recouvrement
DROP TABLE IF EXISTS `n_periodes_recouvrement`;
CREATE TABLE `n_periodes_recouvrement` (
  `pr_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pr_type` enum('examen','rattrapage','pfe','pfc') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pr_centre_id` bigint unsigned NOT NULL,
  `pr_date_debut` date NOT NULL,
  `pr_date_fin` date NOT NULL,
  `pr_niveau_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pr_id`),
  KEY `n_periodes_recouvrement_pr_niveau_id_foreign` (`pr_niveau_id`),
  KEY `n_periodes_recouvrement_pr_centre_id_pr_date_debut_index` (`pr_centre_id`,`pr_date_debut`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_periodes_recouvrement_pr_centre_id_foreign` FOREIGN KEY (`pr_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_periodes_recouvrement_pr_niveau_id_foreign` FOREIGN KEY (`pr_niveau_id`) REFERENCES `n_niveaux` (`niv_id`),
  CONSTRAINT `chk_pr_dates` CHECK ((`pr_date_fin` >= `pr_date_debut`)),
  CONSTRAINT `chk_pr_niveau` CHECK (((`pr_niveau_id` is null) or (`pr_type` in ('pfe','pfc'))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_permissions
DROP TABLE IF EXISTS `n_permissions`;
CREATE TABLE `n_permissions` (
  `perm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `perm_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `perm_nom` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `perm_module` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `perm_type` enum('menu','action','option') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'action',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`perm_id`),
  UNIQUE KEY `n_permissions_perm_code_unique` (`perm_code`),
  KEY `n_permissions_perm_module_index` (`perm_module`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_personnel
DROP TABLE IF EXISTS `n_personnel`;
CREATE TABLE `n_personnel` (
  `pers_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pers_matricule` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_civilite` enum('M','MME','MLLE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pers_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pers_sexe` enum('M','F') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pers_cin` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_date_naissance` date DEFAULT NULL,
  `pers_ville_naissance_id` bigint unsigned DEFAULT NULL,
  `pers_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_ville_id` bigint unsigned DEFAULT NULL,
  `pers_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_cnss` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_situation_familiale` enum('celibataire','marie','divorce','veuf') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_nb_enfants` tinyint unsigned NOT NULL DEFAULT '0',
  `pers_contact_urgence` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_banque` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_rib` varchar(34) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_date_entree` date DEFAULT NULL,
  `pers_date_depart` date DEFAULT NULL,
  `pers_motif_depart` enum('demission','fin_contrat','licenciement','retraite','rupture_conventionnelle','deces','autre') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_commentaire_depart` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pers_user_id` bigint unsigned DEFAULT NULL,
  `pers_site_id` bigint unsigned DEFAULT NULL,
  `pers_centre_id` bigint unsigned DEFAULT NULL,
  `pers_service_id` bigint unsigned DEFAULT NULL,
  `pers_poste_id` bigint unsigned DEFAULT NULL,
  `pers_manager_id` bigint unsigned DEFAULT NULL,
  `pers_prof_id` bigint unsigned DEFAULT NULL,
  `pers_photo_fichier_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pers_id`),
  UNIQUE KEY `n_personnel_pers_cin_unique` (`pers_cin`),
  UNIQUE KEY `n_personnel_pers_user_id_unique` (`pers_user_id`),
  UNIQUE KEY `n_personnel_pers_matricule_unique` (`pers_matricule`),
  UNIQUE KEY `n_personnel_pers_prof_id_unique` (`pers_prof_id`),
  KEY `n_personnel_pers_ville_naissance_id_foreign` (`pers_ville_naissance_id`),
  KEY `n_personnel_pers_ville_id_foreign` (`pers_ville_id`),
  KEY `n_personnel_pers_site_id_foreign` (`pers_site_id`),
  KEY `n_personnel_pers_photo_fichier_id_foreign` (`pers_photo_fichier_id`),
  KEY `n_personnel_created_by_foreign` (`created_by`),
  KEY `n_personnel_updated_by_foreign` (`updated_by`),
  KEY `n_personnel_pers_service_id_foreign` (`pers_service_id`),
  KEY `n_personnel_pers_poste_id_foreign` (`pers_poste_id`),
  KEY `n_personnel_pers_manager_id_foreign` (`pers_manager_id`),
  KEY `n_personnel_pers_centre_id_pers_date_depart_index` (`pers_centre_id`,`pers_date_depart`),
  CONSTRAINT `n_personnel_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_centre_id_foreign` FOREIGN KEY (`pers_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_personnel_pers_manager_id_foreign` FOREIGN KEY (`pers_manager_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_photo_fichier_id_foreign` FOREIGN KEY (`pers_photo_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_poste_id_foreign` FOREIGN KEY (`pers_poste_id`) REFERENCES `n_rh_postes` (`pst_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_prof_id_foreign` FOREIGN KEY (`pers_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_service_id_foreign` FOREIGN KEY (`pers_service_id`) REFERENCES `n_rh_services` (`svc_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_site_id_foreign` FOREIGN KEY (`pers_site_id`) REFERENCES `n_sites` (`site_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_user_id_foreign` FOREIGN KEY (`pers_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_personnel_pers_ville_id_foreign` FOREIGN KEY (`pers_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_personnel_pers_ville_naissance_id_foreign` FOREIGN KEY (`pers_ville_naissance_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_personnel_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pfc
DROP TABLE IF EXISTS `n_pfc`;
CREATE TABLE `n_pfc` (
  `pfc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pfc_inscription_id` bigint unsigned NOT NULL,
  `pfc_classe_id` bigint unsigned NOT NULL,
  `pfc_fichier_id` bigint unsigned DEFAULT NULL,
  `pfc_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pfc_id`),
  KEY `n_pfc_pfc_classe_id_foreign` (`pfc_classe_id`),
  KEY `n_pfc_pfc_fichier_id_foreign` (`pfc_fichier_id`),
  KEY `n_pfc_pfc_inscription_id_index` (`pfc_inscription_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_pfc_pfc_classe_id_foreign` FOREIGN KEY (`pfc_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_pfc_pfc_fichier_id_foreign` FOREIGN KEY (`pfc_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pfc_pfc_inscription_id_foreign` FOREIGN KEY (`pfc_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pfe
DROP TABLE IF EXISTS `n_pfe`;
CREATE TABLE `n_pfe` (
  `pfe_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pfe_inscription_id` bigint unsigned NOT NULL,
  `pfe_classe_id` bigint unsigned NOT NULL,
  `pfe_fichier_id` bigint unsigned DEFAULT NULL,
  `pfe_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pfe_id`),
  KEY `n_pfe_pfe_classe_id_foreign` (`pfe_classe_id`),
  KEY `n_pfe_pfe_fichier_id_foreign` (`pfe_fichier_id`),
  KEY `n_pfe_pfe_inscription_id_index` (`pfe_inscription_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_pfe_pfe_classe_id_foreign` FOREIGN KEY (`pfe_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_pfe_pfe_fichier_id_foreign` FOREIGN KEY (`pfe_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pfe_pfe_inscription_id_foreign` FOREIGN KEY (`pfe_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pieces
DROP TABLE IF EXISTS `n_pieces`;
CREATE TABLE `n_pieces` (
  `pc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pc_type_id` bigint unsigned NOT NULL,
  `pc_recu_id` bigint unsigned DEFAULT NULL,
  `pc_reference` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pc_date` date DEFAULT NULL,
  `pc_montant` decimal(12,2) NOT NULL,
  `pc_titulaire` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pc_banque_id` bigint unsigned DEFAULT NULL,
  `pc_cs_id` bigint unsigned DEFAULT NULL,
  `pc_bordereau_id` bigint unsigned DEFAULT NULL,
  `pc_date_reception` datetime DEFAULT NULL,
  `pc_date_remise` datetime DEFAULT NULL,
  `pc_statut` enum('en_attente','acceptee','rejetee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'en_attente',
  `pc_date_statut` datetime DEFAULT NULL,
  `pc_statut_par` bigint unsigned DEFAULT NULL,
  `pc_piece_remplacee_id` bigint unsigned DEFAULT NULL,
  `pc_commentaire` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pc_capture_fichier_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pc_id`),
  UNIQUE KEY `n_pieces_pc_piece_remplacee_id_unique` (`pc_piece_remplacee_id`),
  KEY `n_pieces_pc_cs_id_foreign` (`pc_cs_id`),
  KEY `n_pieces_pc_statut_par_foreign` (`pc_statut_par`),
  KEY `n_pieces_pc_capture_fichier_id_foreign` (`pc_capture_fichier_id`),
  KEY `n_pieces_pc_type_id_pc_reference_index` (`pc_type_id`,`pc_reference`),
  KEY `n_pieces_pc_statut_index` (`pc_statut`),
  KEY `n_pieces_created_by_foreign` (`created_by`),
  KEY `n_pieces_updated_by_foreign` (`updated_by`),
  KEY `n_pieces_pc_banque_id_foreign` (`pc_banque_id`),
  KEY `n_pieces_pc_bordereau_id_foreign` (`pc_bordereau_id`),
  KEY `n_pieces_pc_recu_id_foreign` (`pc_recu_id`),
  CONSTRAINT `n_pieces_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pieces_pc_banque_id_foreign` FOREIGN KEY (`pc_banque_id`) REFERENCES `n_banques` (`bnk_id`),
  CONSTRAINT `n_pieces_pc_bordereau_id_foreign` FOREIGN KEY (`pc_bordereau_id`) REFERENCES `n_bordereaux_remise` (`bdr_id`),
  CONSTRAINT `n_pieces_pc_capture_fichier_id_foreign` FOREIGN KEY (`pc_capture_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pieces_pc_cs_id_foreign` FOREIGN KEY (`pc_cs_id`) REFERENCES `n_comptes_societe` (`cs_id`),
  CONSTRAINT `n_pieces_pc_piece_remplacee_id_foreign` FOREIGN KEY (`pc_piece_remplacee_id`) REFERENCES `n_pieces` (`pc_id`),
  CONSTRAINT `n_pieces_pc_recu_id_foreign` FOREIGN KEY (`pc_recu_id`) REFERENCES `n_recus` (`rec_id`),
  CONSTRAINT `n_pieces_pc_statut_par_foreign` FOREIGN KEY (`pc_statut_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pieces_pc_type_id_foreign` FOREIGN KEY (`pc_type_id`) REFERENCES `n_types_pieces` (`tpc_id`),
  CONSTRAINT `n_pieces_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_pc_montant` CHECK ((`pc_montant` >= 0)),
  CONSTRAINT `chk_pc_statut_date` CHECK (((`pc_statut` = 'en_attente') or (`pc_date_statut` is not null)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_plafonds_remises
DROP TABLE IF EXISTS `n_plafonds_remises`;
CREATE TABLE `n_plafonds_remises` (
  `plr_role_id` bigint unsigned NOT NULL,
  `plr_pourcentage_max` decimal(5,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`plr_role_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_plafonds_remises_plr_role_id_foreign` FOREIGN KEY (`plr_role_id`) REFERENCES `n_roles` (`role_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_plr` CHECK ((`plr_pourcentage_max` between 0 and 100))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_plan_echeances
DROP TABLE IF EXISTS `n_plan_echeances`;
CREATE TABLE `n_plan_echeances` (
  `ple_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ple_plp_id` bigint unsigned NOT NULL,
  `ple_ordre` smallint unsigned NOT NULL,
  `ple_libelle` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `ple_date_echeance` date NOT NULL,
  `ple_pourcentage` decimal(7,4) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ple_id`),
  UNIQUE KEY `ple_plan_ordre` (`ple_plp_id`,`ple_ordre`),
  KEY `n_plan_echeances_created_by_index` (`created_by`),
  CONSTRAINT `n_plan_echeances_ple_plp_id_foreign` FOREIGN KEY (`ple_plp_id`) REFERENCES `n_plans_paiement` (`plp_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_ple_pourcentage` CHECK (((`ple_pourcentage` >= 0) and (`ple_pourcentage` <= 100)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_plans_paiement
DROP TABLE IF EXISTS `n_plans_paiement`;
CREATE TABLE `n_plans_paiement` (
  `plp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `plp_nom` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `plp_as_id` bigint unsigned NOT NULL,
  `plp_diplome_id` bigint unsigned NOT NULL,
  `plp_mode_id` bigint unsigned NOT NULL,
  `plp_typefrais_id` bigint unsigned NOT NULL,
  `plp_typeperiode_id` bigint unsigned DEFAULT NULL,
  `plp_date_debut` date NOT NULL,
  `plp_date_fin` date NOT NULL,
  `plp_jour_echeance` tinyint unsigned NOT NULL DEFAULT '10',
  `plp_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`plp_id`),
  KEY `n_plans_paiement_plp_typefrais_id_foreign` (`plp_typefrais_id`),
  KEY `n_plans_paiement_plp_typeperiode_id_foreign` (`plp_typeperiode_id`),
  KEY `n_plans_paiement_created_by_index` (`created_by`),
  KEY `n_plans_paiement_plp_diplome_id_foreign` (`plp_diplome_id`),
  KEY `n_plans_paiement_plp_mode_id_foreign` (`plp_mode_id`),
  KEY `plp_recherche` (`plp_as_id`,`plp_diplome_id`,`plp_mode_id`),
  CONSTRAINT `n_plans_paiement_plp_as_id_foreign` FOREIGN KEY (`plp_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_plans_paiement_plp_diplome_id_foreign` FOREIGN KEY (`plp_diplome_id`) REFERENCES `n_diplomes` (`dip_id`),
  CONSTRAINT `n_plans_paiement_plp_mode_id_foreign` FOREIGN KEY (`plp_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_plans_paiement_plp_typefrais_id_foreign` FOREIGN KEY (`plp_typefrais_id`) REFERENCES `n_types_frais` (`tpf_id`),
  CONSTRAINT `n_plans_paiement_plp_typeperiode_id_foreign` FOREIGN KEY (`plp_typeperiode_id`) REFERENCES `n_types_periodes_frais` (`tp_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preferences_notifications
DROP TABLE IF EXISTS `n_preferences_notifications`;
CREATE TABLE `n_preferences_notifications` (
  `pn_user_id` bigint unsigned NOT NULL,
  `pn_type` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pn_email` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pn_user_id`,`pn_type`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preferences_notifications_pn_user_id_foreign` FOREIGN KEY (`pn_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_criteres
DROP TABLE IF EXISTS `n_preinscription_criteres`;
CREATE TABLE `n_preinscription_criteres` (
  `pc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pc_preins_id` bigint unsigned NOT NULL,
  `pc_ca_id` bigint unsigned NOT NULL,
  `pc_sc_id` bigint unsigned NOT NULL,
  `pc_est_obligatoire` tinyint(1) NOT NULL DEFAULT '1',
  `pc_fichier_id` bigint unsigned DEFAULT NULL,
  `pc_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pc_valide_par` bigint unsigned DEFAULT NULL,
  `pc_valide_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pc_id`),
  UNIQUE KEY `n_preinscription_criteres_pc_preins_id_pc_ca_id_unique` (`pc_preins_id`,`pc_ca_id`),
  KEY `n_preinscription_criteres_pc_ca_id_foreign` (`pc_ca_id`),
  KEY `n_preinscription_criteres_pc_sc_id_foreign` (`pc_sc_id`),
  KEY `n_preinscription_criteres_pc_fichier_id_foreign` (`pc_fichier_id`),
  KEY `n_preinscription_criteres_pc_valide_par_foreign` (`pc_valide_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preinscription_criteres_pc_ca_id_foreign` FOREIGN KEY (`pc_ca_id`) REFERENCES `n_criteres_access` (`ca_id`),
  CONSTRAINT `n_preinscription_criteres_pc_fichier_id_foreign` FOREIGN KEY (`pc_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_preinscription_criteres_pc_preins_id_foreign` FOREIGN KEY (`pc_preins_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_preinscription_criteres_pc_sc_id_foreign` FOREIGN KEY (`pc_sc_id`) REFERENCES `n_statuts_criteres` (`sc_id`),
  CONSTRAINT `n_preinscription_criteres_pc_valide_par_foreign` FOREIGN KEY (`pc_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_criteres_hist
DROP TABLE IF EXISTS `n_preinscription_criteres_hist`;
CREATE TABLE `n_preinscription_criteres_hist` (
  `pch_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pch_pc_id` bigint unsigned NOT NULL,
  `pch_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pch_id`),
  KEY `n_preinscription_criteres_hist_pch_pc_id_foreign` (`pch_pc_id`),
  KEY `n_preinscription_criteres_hist_pch_fichier_id_foreign` (`pch_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preinscription_criteres_hist_pch_fichier_id_foreign` FOREIGN KEY (`pch_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_preinscription_criteres_hist_pch_pc_id_foreign` FOREIGN KEY (`pch_pc_id`) REFERENCES `n_preinscription_criteres` (`pc_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_demandes
DROP TABLE IF EXISTS `n_preinscription_demandes`;
CREATE TABLE `n_preinscription_demandes` (
  `pd_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pd_email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pd_civilite` varchar(4) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pd_nom` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pd_prenom` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pd_tel` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pd_whatsapp` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pd_centre_id` bigint unsigned NOT NULL,
  `pd_classe_id` bigint unsigned NOT NULL,
  `pd_annee_id` bigint unsigned NOT NULL,
  `pd_langue` char(2) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
  `pd_token_hash` char(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pd_expire_le` timestamp NULL DEFAULT NULL,
  `pd_envoyee_le` timestamp NULL DEFAULT NULL,
  `pd_nb_envois` smallint unsigned NOT NULL DEFAULT '0',
  `pd_verifie_le` timestamp NULL DEFAULT NULL,
  `pd_consommee_le` timestamp NULL DEFAULT NULL,
  `pd_pre_id` bigint unsigned DEFAULT NULL,
  `pd_cgu_acceptees_le` timestamp NULL DEFAULT NULL,
  `pd_ip` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pd_id`),
  UNIQUE KEY `n_preinscription_demandes_pd_email_unique` (`pd_email`),
  UNIQUE KEY `n_preinscription_demandes_pd_token_hash_unique` (`pd_token_hash`),
  KEY `n_preinscription_demandes_pd_centre_id_foreign` (`pd_centre_id`),
  KEY `n_preinscription_demandes_pd_classe_id_foreign` (`pd_classe_id`),
  KEY `n_preinscription_demandes_pd_annee_id_foreign` (`pd_annee_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preinscription_demandes_pd_annee_id_foreign` FOREIGN KEY (`pd_annee_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_preinscription_demandes_pd_centre_id_foreign` FOREIGN KEY (`pd_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_preinscription_demandes_pd_classe_id_foreign` FOREIGN KEY (`pd_classe_id`) REFERENCES `n_classes` (`classe_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_journal
DROP TABLE IF EXISTS `n_preinscription_journal`;
CREATE TABLE `n_preinscription_journal` (
  `trc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `trc_pre_id` bigint unsigned NOT NULL,
  `trc_user_id` bigint unsigned DEFAULT NULL,
  `trc_action` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trc_description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `trc_donnees` json DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`trc_id`),
  KEY `n_preinscription_journal_trc_pre_id_foreign` (`trc_pre_id`),
  KEY `n_preinscription_journal_trc_user_id_foreign` (`trc_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preinscription_journal_trc_pre_id_foreign` FOREIGN KEY (`trc_pre_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_preinscription_journal_trc_user_id_foreign` FOREIGN KEY (`trc_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_mails_echecs
DROP TABLE IF EXISTS `n_preinscription_mails_echecs`;
CREATE TABLE `n_preinscription_mails_echecs` (
  `pme_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pme_email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pme_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pme_demande_id` bigint unsigned DEFAULT NULL,
  `pme_pre_id` bigint unsigned DEFAULT NULL,
  `pme_erreur` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pme_id`),
  KEY `n_preinscription_mails_echecs_pme_email_index` (`pme_email`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscription_tags
DROP TABLE IF EXISTS `n_preinscription_tags`;
CREATE TABLE `n_preinscription_tags` (
  `pt_pre_id` bigint unsigned NOT NULL,
  `pt_tag_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pt_pre_id`,`pt_tag_id`),
  KEY `n_preinscription_tags_pt_tag_id_foreign` (`pt_tag_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_preinscription_tags_pt_pre_id_foreign` FOREIGN KEY (`pt_pre_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_preinscription_tags_pt_tag_id_foreign` FOREIGN KEY (`pt_tag_id`) REFERENCES `n_tags` (`tag_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_preinscriptions
DROP TABLE IF EXISTS `n_preinscriptions`;
CREATE TABLE `n_preinscriptions` (
  `pre_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pre_seq` int unsigned DEFAULT NULL,
  `pre_numero` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_as_id` bigint unsigned NOT NULL,
  `pre_source` enum('D','A','P','C') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'D',
  `pre_civilite` enum('M','MME','MLLE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pre_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pre_nom_ar` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_prenom_ar` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_sexe` enum('M','F') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_date_naissance` date DEFAULT NULL,
  `pre_ville_naissance_id` bigint unsigned DEFAULT NULL,
  `pre_nat_id` bigint unsigned DEFAULT NULL,
  `pre_cin` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_passeport` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_code_massar` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_situation_famille` enum('C','M','D','V') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_est_handicape` tinyint(1) DEFAULT NULL,
  `pre_est_salarie` tinyint(1) DEFAULT NULL,
  `pre_pere_affilie_cnss` tinyint(1) DEFAULT NULL,
  `pre_email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_whatsapp` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_ville_id` bigint unsigned DEFAULT NULL,
  `pre_langue` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fr',
  `pre_photo_fichier_id` bigint unsigned DEFAULT NULL,
  `pre_type_bac_id` bigint unsigned DEFAULT NULL,
  `pre_serie_bac_id` bigint unsigned DEFAULT NULL,
  `pre_bac_annee` smallint unsigned DEFAULT NULL,
  `pre_bac_mention_id` bigint unsigned DEFAULT NULL,
  `pre_bac_etablissement` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_bac_pays_id` bigint unsigned DEFAULT NULL,
  `pre_bac_ville_id` bigint unsigned DEFAULT NULL,
  `pre_centre_id` bigint unsigned NOT NULL,
  `pre_site_id` bigint unsigned DEFAULT NULL,
  `pre_niv_id` bigint unsigned DEFAULT NULL,
  `pre_for_id` bigint unsigned DEFAULT NULL,
  `pre_classe_id` bigint unsigned DEFAULT NULL,
  `pre_mode_id` bigint unsigned DEFAULT NULL,
  `pre_garant_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_garant_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_camp_id` bigint unsigned DEFAULT NULL,
  `pre_partenaire_id` bigint unsigned DEFAULT NULL,
  `pre_commercial_id` bigint unsigned DEFAULT NULL,
  `pre_utilisateur_id` bigint unsigned DEFAULT NULL,
  `pre_statut_prospect_id` bigint unsigned DEFAULT NULL,
  `pre_canal_id` bigint unsigned DEFAULT NULL,
  `pre_canal_precision` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_droit_modif` tinyint(1) NOT NULL DEFAULT '1',
  `pre_cgu_version` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pre_cgu_acceptees_le` timestamp NULL DEFAULT NULL,
  `pre_soumise_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `pre_derniere_action_le` datetime DEFAULT NULL,
  `pre_tags` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`pre_id`),
  UNIQUE KEY `n_preinscriptions_pre_as_id_pre_seq_unique` (`pre_as_id`,`pre_seq`),
  UNIQUE KEY `n_preinscriptions_pre_numero_unique` (`pre_numero`),
  KEY `n_preinscriptions_pre_ville_naissance_id_foreign` (`pre_ville_naissance_id`),
  KEY `n_preinscriptions_pre_nat_id_foreign` (`pre_nat_id`),
  KEY `n_preinscriptions_pre_ville_id_foreign` (`pre_ville_id`),
  KEY `n_preinscriptions_pre_photo_fichier_id_foreign` (`pre_photo_fichier_id`),
  KEY `n_preinscriptions_pre_type_bac_id_foreign` (`pre_type_bac_id`),
  KEY `n_preinscriptions_pre_serie_bac_id_foreign` (`pre_serie_bac_id`),
  KEY `n_preinscriptions_pre_bac_mention_id_foreign` (`pre_bac_mention_id`),
  KEY `n_preinscriptions_pre_bac_pays_id_foreign` (`pre_bac_pays_id`),
  KEY `n_preinscriptions_pre_bac_ville_id_foreign` (`pre_bac_ville_id`),
  KEY `n_preinscriptions_pre_centre_id_foreign` (`pre_centre_id`),
  KEY `n_preinscriptions_pre_niv_id_foreign` (`pre_niv_id`),
  KEY `n_preinscriptions_pre_classe_id_foreign` (`pre_classe_id`),
  KEY `n_preinscriptions_pre_mode_id_foreign` (`pre_mode_id`),
  KEY `n_preinscriptions_pre_camp_id_foreign` (`pre_camp_id`),
  KEY `n_preinscriptions_pre_partenaire_id_foreign` (`pre_partenaire_id`),
  KEY `n_preinscriptions_pre_commercial_id_foreign` (`pre_commercial_id`),
  KEY `n_preinscriptions_pre_statut_prospect_id_foreign` (`pre_statut_prospect_id`),
  KEY `n_preinscriptions_pre_canal_id_foreign` (`pre_canal_id`),
  KEY `n_preinscriptions_pre_as_id_pre_centre_id_index` (`pre_as_id`,`pre_centre_id`),
  KEY `fk_pre_formation_centre` (`pre_for_id`,`pre_centre_id`),
  KEY `fk_pre_site_centre` (`pre_site_id`,`pre_centre_id`),
  KEY `n_preinscriptions_pre_cin_index` (`pre_cin`),
  KEY `n_preinscriptions_pre_passeport_index` (`pre_passeport`),
  KEY `n_preinscriptions_pre_code_massar_index` (`pre_code_massar`),
  KEY `n_preinscriptions_pre_email_index` (`pre_email`),
  KEY `n_preinscriptions_pre_tel_index` (`pre_tel`),
  KEY `n_preinscriptions_created_by_foreign` (`created_by`),
  KEY `n_preinscriptions_updated_by_foreign` (`updated_by`),
  KEY `idx_pre_utilisateur` (`pre_utilisateur_id`),
  KEY `n_preinscriptions_pre_derniere_action_le_index` (`pre_derniere_action_le`),
  CONSTRAINT `fk_pre_formation_centre` FOREIGN KEY (`pre_for_id`, `pre_centre_id`) REFERENCES `n_formations` (`for_id`, `for_centre_id`),
  CONSTRAINT `fk_pre_site_centre` FOREIGN KEY (`pre_site_id`, `pre_centre_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_preinscriptions_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_preinscriptions_pre_as_id_foreign` FOREIGN KEY (`pre_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_preinscriptions_pre_bac_mention_id_foreign` FOREIGN KEY (`pre_bac_mention_id`) REFERENCES `n_mentions` (`men_id`),
  CONSTRAINT `n_preinscriptions_pre_bac_pays_id_foreign` FOREIGN KEY (`pre_bac_pays_id`) REFERENCES `n_pays` (`pays_id`),
  CONSTRAINT `n_preinscriptions_pre_bac_ville_id_foreign` FOREIGN KEY (`pre_bac_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_preinscriptions_pre_camp_id_foreign` FOREIGN KEY (`pre_camp_id`) REFERENCES `n_campagnes` (`camp_id`),
  CONSTRAINT `n_preinscriptions_pre_canal_id_foreign` FOREIGN KEY (`pre_canal_id`) REFERENCES `n_canaux` (`canal_id`),
  CONSTRAINT `n_preinscriptions_pre_centre_id_foreign` FOREIGN KEY (`pre_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_preinscriptions_pre_classe_id_foreign` FOREIGN KEY (`pre_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_preinscriptions_pre_commercial_id_foreign` FOREIGN KEY (`pre_commercial_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_preinscriptions_pre_mode_id_foreign` FOREIGN KEY (`pre_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_preinscriptions_pre_nat_id_foreign` FOREIGN KEY (`pre_nat_id`) REFERENCES `n_nationalites` (`nat_id`),
  CONSTRAINT `n_preinscriptions_pre_niv_id_foreign` FOREIGN KEY (`pre_niv_id`) REFERENCES `n_niveaux` (`niv_id`),
  CONSTRAINT `n_preinscriptions_pre_partenaire_id_foreign` FOREIGN KEY (`pre_partenaire_id`) REFERENCES `n_partenaires` (`par_id`),
  CONSTRAINT `n_preinscriptions_pre_photo_fichier_id_foreign` FOREIGN KEY (`pre_photo_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_preinscriptions_pre_serie_bac_id_foreign` FOREIGN KEY (`pre_serie_bac_id`) REFERENCES `n_series_bac` (`sb_id`),
  CONSTRAINT `n_preinscriptions_pre_statut_prospect_id_foreign` FOREIGN KEY (`pre_statut_prospect_id`) REFERENCES `n_statuts_prospect` (`stp_id`),
  CONSTRAINT `n_preinscriptions_pre_type_bac_id_foreign` FOREIGN KEY (`pre_type_bac_id`) REFERENCES `n_types_bac` (`tb_id`),
  CONSTRAINT `n_preinscriptions_pre_utilisateur_id_foreign` FOREIGN KEY (`pre_utilisateur_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_preinscriptions_pre_ville_id_foreign` FOREIGN KEY (`pre_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_preinscriptions_pre_ville_naissance_id_foreign` FOREIGN KEY (`pre_ville_naissance_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_preinscriptions_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_pre_bac_annee` CHECK (((`pre_bac_annee` is null) or (`pre_bac_annee` between 1950 and 2100)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_prof_convenu
DROP TABLE IF EXISTS `n_prof_convenu`;
CREATE TABLE `n_prof_convenu` (
  `pfc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pfc_prof_id` bigint unsigned NOT NULL,
  `pfc_emo_id` bigint unsigned NOT NULL,
  `pfc_as_id` bigint unsigned NOT NULL,
  `pfc_volume_horaire` decimal(6,2) DEFAULT NULL,
  `pfc_date_deb` date NOT NULL,
  `pfc_date_fin` date NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pfc_id`),
  UNIQUE KEY `n_prof_convenu_pfc_prof_id_pfc_emo_id_pfc_as_id_unique` (`pfc_prof_id`,`pfc_emo_id`,`pfc_as_id`),
  KEY `n_prof_convenu_pfc_emo_id_foreign` (`pfc_emo_id`),
  KEY `n_prof_convenu_pfc_as_id_foreign` (`pfc_as_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_prof_convenu_pfc_as_id_foreign` FOREIGN KEY (`pfc_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_prof_convenu_pfc_emo_id_foreign` FOREIGN KEY (`pfc_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_prof_convenu_pfc_prof_id_foreign` FOREIGN KEY (`pfc_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_pfc_dates` CHECK ((`pfc_date_fin` >= `pfc_date_deb`)),
  CONSTRAINT `chk_pfc_volume` CHECK (((`pfc_volume_horaire` is null) or (`pfc_volume_horaire` >= 0)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_prof_elements
DROP TABLE IF EXISTS `n_prof_elements`;
CREATE TABLE `n_prof_elements` (
  `pe_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pe_emo_id` bigint unsigned NOT NULL,
  `pe_prof_id` bigint unsigned NOT NULL,
  `pe_mode_id` bigint unsigned NOT NULL,
  `pe_grp_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `pe_grp_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`pe_grp_id`,0)) VIRTUAL,
  PRIMARY KEY (`pe_id`),
  UNIQUE KEY `uq_pe_emo_mode_grp` (`pe_emo_id`,`pe_mode_id`,`pe_grp_key`),
  KEY `n_prof_elements_pe_prof_id_foreign` (`pe_prof_id`),
  KEY `n_prof_elements_pe_mode_id_foreign` (`pe_mode_id`),
  KEY `n_prof_elements_pe_grp_id_foreign` (`pe_grp_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_prof_elements_pe_emo_id_foreign` FOREIGN KEY (`pe_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE,
  CONSTRAINT `n_prof_elements_pe_grp_id_foreign` FOREIGN KEY (`pe_grp_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE CASCADE,
  CONSTRAINT `n_prof_elements_pe_mode_id_foreign` FOREIGN KEY (`pe_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_prof_elements_pe_prof_id_foreign` FOREIGN KEY (`pe_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_profil_composantes
DROP TABLE IF EXISTS `n_profil_composantes`;
CREATE TABLE `n_profil_composantes` (
  `pco_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pco_pev_id` bigint unsigned NOT NULL,
  `pco_type_exam_id` bigint unsigned NOT NULL,
  `pco_poids` decimal(5,2) NOT NULL DEFAULT '0.00',
  `pco_portee` enum('element','uf','semestre') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'element',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pco_id`),
  UNIQUE KEY `uq_pco` (`pco_pev_id`,`pco_type_exam_id`,`pco_portee`),
  KEY `n_profil_composantes_pco_type_exam_id_foreign` (`pco_type_exam_id`),
  KEY `n_profil_composantes_created_by_index` (`created_by`),
  CONSTRAINT `n_profil_composantes_pco_pev_id_foreign` FOREIGN KEY (`pco_pev_id`) REFERENCES `n_profils_evaluation` (`pev_id`) ON DELETE CASCADE,
  CONSTRAINT `n_profil_composantes_pco_type_exam_id_foreign` FOREIGN KEY (`pco_type_exam_id`) REFERENCES `n_types_examens` (`tpe_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_profils_evaluation
DROP TABLE IF EXISTS `n_profils_evaluation`;
CREATE TABLE `n_profils_evaluation` (
  `pev_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pev_nom` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pev_niveau_validation` enum('element','uf','semestre') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'uf',
  `pev_seuil_validation` decimal(4,2) NOT NULL DEFAULT '10.00',
  `pev_note_eliminatoire` decimal(4,2) DEFAULT NULL,
  `pev_compensation` tinyint(1) NOT NULL DEFAULT '1',
  `pev_moyenne_cc` enum('coefficient','heures','simple') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'heures',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `pev_est_defaut` tinyint(1) NOT NULL DEFAULT '0',
  `pev_est_predefini` tinyint(1) NOT NULL DEFAULT '0',
  `pev_ignorer_composante_absente` tinyint(1) NOT NULL DEFAULT '0',
  `pev_description` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`pev_id`),
  KEY `n_profils_evaluation_created_by_index` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pv_access
DROP TABLE IF EXISTS `n_pv_access`;
CREATE TABLE `n_pv_access` (
  `pva_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pva_diplome_id` bigint unsigned NOT NULL,
  `pva_niveau_filiere` tinyint unsigned NOT NULL,
  `pva_mise_a_niveau` tinyint(1) NOT NULL DEFAULT '0',
  `pva_type_access` enum('D','P') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `pva_modele_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pva_id`),
  UNIQUE KEY `uq_pva` (`pva_diplome_id`,`pva_niveau_filiere`,`pva_mise_a_niveau`,`pva_type_access`),
  KEY `n_pv_access_pva_modele_id_index` (`pva_modele_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_pv_access_pva_diplome_id_foreign` FOREIGN KEY (`pva_diplome_id`) REFERENCES `n_diplomes` (`dip_id`),
  CONSTRAINT `n_pv_access_pva_modele_id_foreign` FOREIGN KEY (`pva_modele_id`) REFERENCES `n_modeles_documents` (`mdoc_id`),
  CONSTRAINT `chk_pva_niveau` CHECK ((`pva_niveau_filiere` between 1 and 10))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pv_chemins
DROP TABLE IF EXISTS `n_pv_chemins`;
CREATE TABLE `n_pv_chemins` (
  `pv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pv_chemin` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `pv_date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pv_id`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pv_deliberations
DROP TABLE IF EXISTS `n_pv_deliberations`;
CREATE TABLE `n_pv_deliberations` (
  `pv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pv_del_id` bigint unsigned NOT NULL,
  `pv_jury_id` bigint unsigned NOT NULL,
  `pv_date` datetime DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pv_id`),
  UNIQUE KEY `uq_pv_del_jury` (`pv_del_id`,`pv_jury_id`),
  KEY `n_pv_deliberations_pv_jury_id_foreign` (`pv_jury_id`),
  KEY `n_pv_deliberations_created_by_foreign` (`created_by`),
  KEY `n_pv_deliberations_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_pv_deliberations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_pv_deliberations_pv_del_id_foreign` FOREIGN KEY (`pv_del_id`) REFERENCES `n_deliberations` (`del_id`) ON DELETE CASCADE,
  CONSTRAINT `n_pv_deliberations_pv_jury_id_foreign` FOREIGN KEY (`pv_jury_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_pv_deliberations_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pv_notes
DROP TABLE IF EXISTS `n_pv_notes`;
CREATE TABLE `n_pv_notes` (
  `pv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pv_classe_id` bigint unsigned NOT NULL,
  `pv_as_id` bigint unsigned NOT NULL,
  `pv_fichier_id` bigint unsigned DEFAULT NULL,
  `pv_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pv_id`),
  UNIQUE KEY `uq_pv_notes_classe_as` (`pv_classe_id`,`pv_as_id`),
  KEY `n_pv_notes_pv_as_id_foreign` (`pv_as_id`),
  KEY `n_pv_notes_pv_fichier_id_foreign` (`pv_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_pv_notes_pv_as_id_foreign` FOREIGN KEY (`pv_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_pv_notes_pv_classe_id_foreign` FOREIGN KEY (`pv_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_pv_notes_pv_fichier_id_foreign` FOREIGN KEY (`pv_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_pv_types
DROP TABLE IF EXISTS `n_pv_types`;
CREATE TABLE `n_pv_types` (
  `pvt_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pvt_centre_id` bigint unsigned DEFAULT NULL,
  `pvt_key` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pvt_nom` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pvt_type` enum('semestre','annee','final','global') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pvt_id`),
  UNIQUE KEY `n_pv_types_pvt_key_unique` (`pvt_key`),
  KEY `n_pv_types_pvt_centre_id_foreign` (`pvt_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_pv_types_pvt_centre_id_foreign` FOREIGN KEY (`pvt_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_recouv_echeances
DROP TABLE IF EXISTS `n_recouv_echeances`;
CREATE TABLE `n_recouv_echeances` (
  `rce_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rce_rcv_id` bigint unsigned NOT NULL,
  `rce_date_echeance` date NOT NULL,
  `rce_montant` decimal(12,2) NOT NULL,
  `rce_statut` enum('non_payee','payee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'non_payee',
  `rce_mp_id` bigint unsigned DEFAULT NULL,
  `rce_recu_id` bigint unsigned DEFAULT NULL,
  `rce_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rce_id`),
  KEY `n_recouv_echeances_rce_mp_id_foreign` (`rce_mp_id`),
  KEY `n_recouv_echeances_rce_recu_id_foreign` (`rce_recu_id`),
  KEY `n_recouv_echeances_rce_rcv_id_rce_date_echeance_index` (`rce_rcv_id`,`rce_date_echeance`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_recouv_echeances_rce_mp_id_foreign` FOREIGN KEY (`rce_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`),
  CONSTRAINT `n_recouv_echeances_rce_rcv_id_foreign` FOREIGN KEY (`rce_rcv_id`) REFERENCES `n_recouvrements` (`rcv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_recouv_echeances_rce_recu_id_foreign` FOREIGN KEY (`rce_recu_id`) REFERENCES `n_recus` (`rec_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rce_montant` CHECK ((`rce_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_recouv_periodes
DROP TABLE IF EXISTS `n_recouv_periodes`;
CREATE TABLE `n_recouv_periodes` (
  `rcp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rcp_rcv_id` bigint unsigned NOT NULL,
  `rcp_pcv_id` bigint unsigned NOT NULL,
  `rcp_impaye` decimal(12,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rcp_id`),
  UNIQUE KEY `n_recouv_periodes_rcp_rcv_id_rcp_pcv_id_unique` (`rcp_rcv_id`,`rcp_pcv_id`),
  KEY `n_recouv_periodes_rcp_pcv_id_foreign` (`rcp_pcv_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_recouv_periodes_rcp_pcv_id_foreign` FOREIGN KEY (`rcp_pcv_id`) REFERENCES `n_periodes_convenues` (`pcv_id`),
  CONSTRAINT `n_recouv_periodes_rcp_rcv_id_foreign` FOREIGN KEY (`rcp_rcv_id`) REFERENCES `n_recouvrements` (`rcv_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_rcp_impaye` CHECK ((`rcp_impaye` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_recouvrements
DROP TABLE IF EXISTS `n_recouvrements`;
CREATE TABLE `n_recouvrements` (
  `rcv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rcv_ins_id` bigint unsigned NOT NULL,
  `rcv_user_id` bigint unsigned NOT NULL,
  `rcv_montant` decimal(12,2) NOT NULL,
  `rcv_statut` enum('ouvert','clos') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ouvert',
  `rcv_date_ouverture` datetime NOT NULL,
  `rcv_date_cloture` datetime DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `rcv_ouvert_key` bigint unsigned GENERATED ALWAYS AS (if((`rcv_statut` = 'ouvert'),`rcv_ins_id`,NULL)) STORED,
  PRIMARY KEY (`rcv_id`),
  UNIQUE KEY `uq_rcv_ouvert` (`rcv_ouvert_key`),
  KEY `n_recouvrements_rcv_ins_id_foreign` (`rcv_ins_id`),
  KEY `n_recouvrements_rcv_user_id_foreign` (`rcv_user_id`),
  KEY `n_recouvrements_created_by_foreign` (`created_by`),
  KEY `n_recouvrements_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_recouvrements_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_recouvrements_rcv_ins_id_foreign` FOREIGN KEY (`rcv_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_recouvrements_rcv_user_id_foreign` FOREIGN KEY (`rcv_user_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_recouvrements_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rcv_cloture` CHECK ((((`rcv_statut` = 'clos') = (`rcv_date_cloture` is not null)) and ((`rcv_date_cloture` is null) or (`rcv_date_cloture` >= `rcv_date_ouverture`)))),
  CONSTRAINT `chk_rcv_montant` CHECK ((`rcv_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_recu_paiements
DROP TABLE IF EXISTS `n_recu_paiements`;
CREATE TABLE `n_recu_paiements` (
  `rp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rp_recu_id` bigint unsigned NOT NULL,
  `rp_mp_id` bigint unsigned NOT NULL,
  `rp_montant` decimal(12,2) NOT NULL,
  `rp_piece_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rp_id`),
  KEY `n_recu_paiements_rp_recu_id_foreign` (`rp_recu_id`),
  KEY `n_recu_paiements_rp_piece_id_foreign` (`rp_piece_id`),
  KEY `n_recu_paiements_rp_mp_id_rp_recu_id_index` (`rp_mp_id`,`rp_recu_id`),
  KEY `n_recu_paiements_created_by_foreign` (`created_by`),
  KEY `n_recu_paiements_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_recu_paiements_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_recu_paiements_rp_mp_id_foreign` FOREIGN KEY (`rp_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`),
  CONSTRAINT `n_recu_paiements_rp_piece_id_foreign` FOREIGN KEY (`rp_piece_id`) REFERENCES `n_pieces` (`pc_id`),
  CONSTRAINT `n_recu_paiements_rp_recu_id_foreign` FOREIGN KEY (`rp_recu_id`) REFERENCES `n_recus` (`rec_id`) ON DELETE CASCADE,
  CONSTRAINT `n_recu_paiements_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rp_montant` CHECK ((`rp_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_recus
DROP TABLE IF EXISTS `n_recus`;
CREATE TABLE `n_recus` (
  `rec_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rec_numero` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rec_numero_ancien` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rec_seq` int unsigned DEFAULT NULL,
  `rec_date` date NOT NULL,
  `rec_montant` decimal(12,2) NOT NULL,
  `rec_inscription_id` bigint unsigned NOT NULL,
  `rec_user_id` bigint unsigned NOT NULL,
  `rec_caisse_id` bigint unsigned DEFAULT NULL,
  `rec_observation` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rec_est_valide` tinyint(1) NOT NULL DEFAULT '1',
  `rec_fichier_id` bigint unsigned DEFAULT NULL,
  `rec_motif_annulation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rec_annule_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rec_id`),
  UNIQUE KEY `n_recus_rec_numero_unique` (`rec_numero`),
  KEY `n_recus_rec_user_id_foreign` (`rec_user_id`),
  KEY `n_recus_rec_caisse_id_foreign` (`rec_caisse_id`),
  KEY `n_recus_rec_fichier_id_foreign` (`rec_fichier_id`),
  KEY `n_recus_rec_annule_par_foreign` (`rec_annule_par`),
  KEY `n_recus_rec_inscription_id_rec_date_index` (`rec_inscription_id`,`rec_date`),
  KEY `n_recus_rec_date_rec_caisse_id_index` (`rec_date`,`rec_caisse_id`),
  KEY `n_recus_rec_numero_ancien_index` (`rec_numero_ancien`),
  KEY `n_recus_rec_seq_index` (`rec_seq`),
  KEY `n_recus_created_by_foreign` (`created_by`),
  KEY `n_recus_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_recus_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_recus_rec_annule_par_foreign` FOREIGN KEY (`rec_annule_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_recus_rec_caisse_id_foreign` FOREIGN KEY (`rec_caisse_id`) REFERENCES `n_caisse` (`caisse_id`),
  CONSTRAINT `n_recus_rec_fichier_id_foreign` FOREIGN KEY (`rec_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_recus_rec_inscription_id_foreign` FOREIGN KEY (`rec_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_recus_rec_user_id_foreign` FOREIGN KEY (`rec_user_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_recus_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rec_annulation` CHECK (((`deleted_at` is null) or (`rec_motif_annulation` is not null))),
  CONSTRAINT `chk_rec_date` CHECK ((`rec_date` between '2000-01-01' and '2100-12-31')),
  CONSTRAINT `chk_rec_montant` CHECK ((`rec_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_reductions
DROP TABLE IF EXISTS `n_reductions`;
CREATE TABLE `n_reductions` (
  `red_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `red_fcv_id` bigint unsigned NOT NULL,
  `red_typereduction_id` bigint unsigned NOT NULL,
  `red_mode` enum('P','M') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `red_valeur` decimal(12,2) NOT NULL,
  `red_commentaire` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `red_accordee_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `red_statut` enum('validee','a_valider','refusee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'validee',
  `red_validee_par` bigint unsigned DEFAULT NULL,
  `red_validee_le` datetime DEFAULT NULL,
  `red_motif_refus` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`red_id`),
  KEY `n_reductions_red_fcv_id_foreign` (`red_fcv_id`),
  KEY `n_reductions_red_typereduction_id_foreign` (`red_typereduction_id`),
  KEY `n_reductions_red_accordee_par_foreign` (`red_accordee_par`),
  KEY `n_reductions_created_by_foreign` (`created_by`),
  KEY `n_reductions_updated_by_foreign` (`updated_by`),
  KEY `n_reductions_red_validee_par_foreign` (`red_validee_par`),
  KEY `n_reductions_red_statut_index` (`red_statut`),
  CONSTRAINT `n_reductions_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_reductions_red_accordee_par_foreign` FOREIGN KEY (`red_accordee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_reductions_red_fcv_id_foreign` FOREIGN KEY (`red_fcv_id`) REFERENCES `n_fraisconvenu` (`fcv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_reductions_red_typereduction_id_foreign` FOREIGN KEY (`red_typereduction_id`) REFERENCES `n_types_reductions` (`tred_id`),
  CONSTRAINT `n_reductions_red_validee_par_foreign` FOREIGN KEY (`red_validee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_reductions_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_red_valeur` CHECK (((`red_valeur` >= 0) and ((`red_mode` = 'M') or (`red_valeur` <= 100))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_regles_evaluation
DROP TABLE IF EXISTS `n_regles_evaluation`;
CREATE TABLE `n_regles_evaluation` (
  `reg_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `reg_libelle` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `reg_diplome_id` bigint unsigned DEFAULT NULL,
  `reg_formation_id` bigint unsigned DEFAULT NULL,
  `reg_as_debut_id` bigint unsigned NOT NULL,
  `reg_as_fin_id` bigint unsigned DEFAULT NULL,
  `reg_seuil_validation_element` decimal(5,2) NOT NULL DEFAULT '10.00',
  `reg_seuil_validation_module` decimal(5,2) NOT NULL DEFAULT '10.00',
  `reg_seuil_validation_semestre` decimal(5,2) NOT NULL DEFAULT '10.00',
  `reg_note_eliminatoire` decimal(5,2) DEFAULT NULL,
  `reg_nb_max_elements_eliminatoires` tinyint unsigned NOT NULL DEFAULT '0',
  `reg_nb_max_elements_sous_seuil` tinyint unsigned DEFAULT NULL,
  `reg_nb_max_modules_sous_seuil` tinyint unsigned DEFAULT '2',
  `reg_element_non_note_eliminatoire` tinyint(1) NOT NULL DEFAULT '1',
  `reg_compensation_modules` tinyint(1) NOT NULL DEFAULT '1',
  `reg_compensation_semestres` tinyint(1) NOT NULL DEFAULT '0',
  `reg_plafond_rattrapage` decimal(5,2) DEFAULT '10.00',
  `reg_plafond_rattrapage_projet` decimal(5,2) DEFAULT '12.00',
  `reg_rattrapage_sans_plafond_si_absence_justifiee` tinyint(1) NOT NULL DEFAULT '1',
  `reg_note_retenue` enum('max_normale_rattrapage','rattrapage_si_present','moyenne') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'max_normale_rattrapage',
  `reg_calcul_semestre` enum('elements','modules') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'elements',
  `reg_ponderation` enum('coefficients','credits') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'coefficients',
  `reg_moyenne_annuelle` enum('ponderee_coefficients','simple') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ponderee_coefficients',
  `reg_somme_coef_epreuves_100` tinyint(1) NOT NULL DEFAULT '1',
  `reg_decimales` tinyint unsigned NOT NULL DEFAULT '2',
  `reg_arrondi` enum('arrondi','troncature') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'arrondi',
  `reg_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `reg_valide_par` bigint unsigned DEFAULT NULL,
  `reg_valide_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `reg_diplome_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`reg_diplome_id`,0)) STORED,
  `reg_formation_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`reg_formation_id`,0)) STORED,
  PRIMARY KEY (`reg_id`),
  UNIQUE KEY `uq_regle` (`reg_diplome_key`,`reg_formation_key`,`reg_as_debut_id`),
  KEY `n_regles_evaluation_reg_diplome_id_foreign` (`reg_diplome_id`),
  KEY `n_regles_evaluation_reg_formation_id_foreign` (`reg_formation_id`),
  KEY `n_regles_evaluation_reg_as_debut_id_foreign` (`reg_as_debut_id`),
  KEY `n_regles_evaluation_reg_as_fin_id_foreign` (`reg_as_fin_id`),
  KEY `n_regles_evaluation_reg_valide_par_foreign` (`reg_valide_par`),
  KEY `n_regles_evaluation_created_by_foreign` (`created_by`),
  KEY `n_regles_evaluation_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_regles_evaluation_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_regles_evaluation_reg_as_debut_id_foreign` FOREIGN KEY (`reg_as_debut_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_regles_evaluation_reg_as_fin_id_foreign` FOREIGN KEY (`reg_as_fin_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_regles_evaluation_reg_diplome_id_foreign` FOREIGN KEY (`reg_diplome_id`) REFERENCES `n_diplomes` (`dip_id`),
  CONSTRAINT `n_regles_evaluation_reg_formation_id_foreign` FOREIGN KEY (`reg_formation_id`) REFERENCES `n_formations` (`for_id`),
  CONSTRAINT `n_regles_evaluation_reg_valide_par_foreign` FOREIGN KEY (`reg_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_regles_evaluation_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_reg_decimales` CHECK ((`reg_decimales` <= 4)),
  CONSTRAINT `chk_reg_eliminatoire` CHECK (((`reg_note_eliminatoire` is null) or (`reg_note_eliminatoire` between 0 and 20))),
  CONSTRAINT `chk_reg_plafonds` CHECK ((((`reg_plafond_rattrapage` is null) or (`reg_plafond_rattrapage` between 0 and 20)) and ((`reg_plafond_rattrapage_projet` is null) or (`reg_plafond_rattrapage_projet` between 0 and 20)))),
  CONSTRAINT `chk_reg_seuil_validation_element` CHECK ((`reg_seuil_validation_element` between 0 and 20)),
  CONSTRAINT `chk_reg_seuil_validation_module` CHECK ((`reg_seuil_validation_module` between 0 and 20)),
  CONSTRAINT `chk_reg_seuil_validation_semestre` CHECK ((`reg_seuil_validation_semestre` between 0 and 20))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_relances
DROP TABLE IF EXISTS `n_relances`;
CREATE TABLE `n_relances` (
  `rel_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rel_pcv_id` bigint unsigned NOT NULL,
  `rel_rcv_id` bigint unsigned DEFAULT NULL,
  `rel_niveau` enum('rappel_avant','relance_1','relance_2','mise_en_demeure') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rel_canal` enum('email','sms','whatsapp','courrier','appel') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rel_destinataire` enum('etudiant','tuteur') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rel_est_automatique` tinyint(1) NOT NULL DEFAULT '1',
  `rel_notif_id` bigint unsigned DEFAULT NULL,
  `rel_montant_du` decimal(12,2) NOT NULL,
  `rel_user_id` bigint unsigned DEFAULT NULL,
  `rel_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rel_id`),
  UNIQUE KEY `uq_relance` (`rel_pcv_id`,`rel_niveau`,`rel_canal`),
  KEY `n_relances_rel_rcv_id_foreign` (`rel_rcv_id`),
  KEY `n_relances_rel_notif_id_foreign` (`rel_notif_id`),
  KEY `n_relances_rel_user_id_foreign` (`rel_user_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_relances_rel_notif_id_foreign` FOREIGN KEY (`rel_notif_id`) REFERENCES `n_notifications` (`notif_id`) ON DELETE SET NULL,
  CONSTRAINT `n_relances_rel_pcv_id_foreign` FOREIGN KEY (`rel_pcv_id`) REFERENCES `n_periodes_convenues` (`pcv_id`) ON DELETE CASCADE,
  CONSTRAINT `n_relances_rel_rcv_id_foreign` FOREIGN KEY (`rel_rcv_id`) REFERENCES `n_recouvrements` (`rcv_id`) ON DELETE SET NULL,
  CONSTRAINT `n_relances_rel_user_id_foreign` FOREIGN KEY (`rel_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rel_montant` CHECK ((`rel_montant_du` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_releves_notes
DROP TABLE IF EXISTS `n_releves_notes`;
CREATE TABLE `n_releves_notes` (
  `rlv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rlv_inscription_id` bigint unsigned NOT NULL,
  `rlv_classe_id` bigint unsigned NOT NULL,
  `rlv_semestre_id` bigint unsigned DEFAULT NULL,
  `rlv_fichier_id` bigint unsigned DEFAULT NULL,
  `rlv_est_archive` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rlv_id`),
  KEY `n_releves_notes_rlv_classe_id_foreign` (`rlv_classe_id`),
  KEY `n_releves_notes_rlv_semestre_id_foreign` (`rlv_semestre_id`),
  KEY `n_releves_notes_rlv_fichier_id_foreign` (`rlv_fichier_id`),
  KEY `n_releves_notes_rlv_inscription_id_rlv_semestre_id_index` (`rlv_inscription_id`,`rlv_semestre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_releves_notes_rlv_classe_id_foreign` FOREIGN KEY (`rlv_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_releves_notes_rlv_fichier_id_foreign` FOREIGN KEY (`rlv_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_releves_notes_rlv_inscription_id_foreign` FOREIGN KEY (`rlv_inscription_id`) REFERENCES `n_inscriptions` (`ins_id`) ON DELETE CASCADE,
  CONSTRAINT `n_releves_notes_rlv_semestre_id_foreign` FOREIGN KEY (`rlv_semestre_id`) REFERENCES `n_semestres` (`sem_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_remarque
DROP TABLE IF EXISTS `n_remarque`;
CREATE TABLE `n_remarque` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `text` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `date` datetime DEFAULT NULL,
  `ins_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned NOT NULL,
  `visible` tinyint(1) NOT NULL DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  `type_id` bigint unsigned NOT NULL DEFAULT '1',
  `preins_id` bigint unsigned DEFAULT NULL,
  `rem_recouvrement` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `n_remarque_ins_id_index` (`ins_id`),
  KEY `n_remarque_user_id_index` (`user_id`),
  KEY `n_remarque_type_id_index` (`type_id`),
  KEY `n_remarque_preins_id_index` (`preins_id`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_remboursements
DROP TABLE IF EXISTS `n_remboursements`;
CREATE TABLE `n_remboursements` (
  `rmb_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rmb_ins_id` bigint unsigned NOT NULL,
  `rmb_montant` decimal(12,2) NOT NULL,
  `rmb_motif` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `rmb_statut` enum('demande','valide','paye','refuse') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'demande',
  `rmb_mp_id` bigint unsigned DEFAULT NULL,
  `rmb_caisse_id` bigint unsigned DEFAULT NULL,
  `rmb_reference` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rmb_motif_refus` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rmb_demande_par` bigint unsigned DEFAULT NULL,
  `rmb_valide_par` bigint unsigned DEFAULT NULL,
  `rmb_valide_le` timestamp NULL DEFAULT NULL,
  `rmb_paye_par` bigint unsigned DEFAULT NULL,
  `rmb_paye_le` date DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rmb_id`),
  KEY `n_remboursements_rmb_ins_id_foreign` (`rmb_ins_id`),
  KEY `n_remboursements_rmb_mp_id_foreign` (`rmb_mp_id`),
  KEY `n_remboursements_rmb_caisse_id_foreign` (`rmb_caisse_id`),
  KEY `n_remboursements_rmb_demande_par_foreign` (`rmb_demande_par`),
  KEY `n_remboursements_rmb_valide_par_foreign` (`rmb_valide_par`),
  KEY `n_remboursements_rmb_paye_par_foreign` (`rmb_paye_par`),
  KEY `n_remboursements_rmb_statut_rmb_ins_id_index` (`rmb_statut`,`rmb_ins_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_remboursements_rmb_caisse_id_foreign` FOREIGN KEY (`rmb_caisse_id`) REFERENCES `n_caisse` (`caisse_id`),
  CONSTRAINT `n_remboursements_rmb_demande_par_foreign` FOREIGN KEY (`rmb_demande_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_remboursements_rmb_ins_id_foreign` FOREIGN KEY (`rmb_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_remboursements_rmb_mp_id_foreign` FOREIGN KEY (`rmb_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`),
  CONSTRAINT `n_remboursements_rmb_paye_par_foreign` FOREIGN KEY (`rmb_paye_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_remboursements_rmb_valide_par_foreign` FOREIGN KEY (`rmb_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rmb_montant` CHECK ((`rmb_montant` > 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rendez_vous
DROP TABLE IF EXISTS `n_rendez_vous`;
CREATE TABLE `n_rendez_vous` (
  `rv_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rv_pre_id` bigint unsigned NOT NULL,
  `rv_hs_id` bigint unsigned DEFAULT NULL,
  `rv_user_id` bigint unsigned DEFAULT NULL,
  `rv_type` enum('telephone','presentiel','visio','whatsapp') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'telephone',
  `rv_date_heure` datetime NOT NULL,
  `rv_lieu_ou_lien` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rv_statut` enum('planifie','confirme','realise','annule','absent') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'planifie',
  `rv_compte_rendu` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rv_id`),
  KEY `n_rendez_vous_rv_pre_id_foreign` (`rv_pre_id`),
  KEY `n_rendez_vous_rv_hs_id_foreign` (`rv_hs_id`),
  KEY `n_rendez_vous_rv_user_id_foreign` (`rv_user_id`),
  KEY `n_rendez_vous_rv_statut_rv_date_heure_index` (`rv_statut`,`rv_date_heure`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rendez_vous_rv_hs_id_foreign` FOREIGN KEY (`rv_hs_id`) REFERENCES `n_historique_statut` (`hs_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rendez_vous_rv_pre_id_foreign` FOREIGN KEY (`rv_pre_id`) REFERENCES `n_preinscriptions` (`pre_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rendez_vous_rv_user_id_foreign` FOREIGN KEY (`rv_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rendu_fichiers
DROP TABLE IF EXISTS `n_rendu_fichiers`;
CREATE TABLE `n_rendu_fichiers` (
  `rf_ren_id` bigint unsigned NOT NULL,
  `rf_fichier_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rf_ren_id`,`rf_fichier_id`),
  KEY `n_rendu_fichiers_rf_fichier_id_foreign` (`rf_fichier_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rendu_fichiers_rf_fichier_id_foreign` FOREIGN KEY (`rf_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_rendu_fichiers_rf_ren_id_foreign` FOREIGN KEY (`rf_ren_id`) REFERENCES `n_rendus` (`ren_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rendus
DROP TABLE IF EXISTS `n_rendus`;
CREATE TABLE `n_rendus` (
  `ren_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ren_dev_id` bigint unsigned NOT NULL,
  `ren_ins_id` bigint unsigned NOT NULL,
  `ren_texte` text COLLATE utf8mb4_unicode_ci,
  `ren_depose_le` timestamp NOT NULL,
  `ren_en_retard` tinyint(1) NOT NULL DEFAULT '0',
  `ren_note` decimal(5,2) DEFAULT NULL,
  `ren_commentaire` text COLLATE utf8mb4_unicode_ci,
  `ren_fichier_corrige_id` bigint unsigned DEFAULT NULL,
  `ren_corrige_le` timestamp NULL DEFAULT NULL,
  `ren_corrige_par` bigint unsigned DEFAULT NULL,
  `ren_publie_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ren_id`),
  UNIQUE KEY `n_rendus_ren_dev_id_ren_ins_id_unique` (`ren_dev_id`,`ren_ins_id`),
  KEY `n_rendus_ren_ins_id_foreign` (`ren_ins_id`),
  KEY `n_rendus_ren_fichier_corrige_id_foreign` (`ren_fichier_corrige_id`),
  KEY `n_rendus_ren_corrige_par_foreign` (`ren_corrige_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rendus_ren_corrige_par_foreign` FOREIGN KEY (`ren_corrige_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rendus_ren_dev_id_foreign` FOREIGN KEY (`ren_dev_id`) REFERENCES `n_devoirs` (`dev_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rendus_ren_fichier_corrige_id_foreign` FOREIGN KEY (`ren_fichier_corrige_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_rendus_ren_ins_id_foreign` FOREIGN KEY (`ren_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `chk_ren_note` CHECK (((`ren_note` is null) or ((`ren_note` >= 0) and (`ren_note` <= 20))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_ressource_chapitres
DROP TABLE IF EXISTS `n_ressource_chapitres`;
CREATE TABLE `n_ressource_chapitres` (
  `rch_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rch_emo_id` bigint unsigned NOT NULL,
  `rch_as_id` bigint unsigned NOT NULL,
  `rch_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `rch_ordre` smallint unsigned NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rch_id`),
  KEY `n_ressource_chapitres_rch_emo_id_foreign` (`rch_emo_id`),
  KEY `n_ressource_chapitres_rch_as_id_foreign` (`rch_as_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_ressource_chapitres_rch_as_id_foreign` FOREIGN KEY (`rch_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_ressource_chapitres_rch_emo_id_foreign` FOREIGN KEY (`rch_emo_id`) REFERENCES `n_elements_modules` (`emo_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_ressources
DROP TABLE IF EXISTS `n_ressources`;
CREATE TABLE `n_ressources` (
  `res_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `res_emo_id` bigint unsigned NOT NULL,
  `res_as_id` bigint unsigned NOT NULL,
  `res_chapitre_id` bigint unsigned DEFAULT NULL,
  `res_groupe_id` bigint unsigned DEFAULT NULL,
  `res_mode_id` bigint unsigned DEFAULT NULL,
  `res_type` enum('fichier','lien','video') COLLATE utf8mb4_unicode_ci NOT NULL,
  `res_titre` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `res_description` text COLLATE utf8mb4_unicode_ci,
  `res_fichier_id` bigint unsigned DEFAULT NULL,
  `res_url` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `res_seance_id` bigint unsigned DEFAULT NULL,
  `res_visible_le` timestamp NULL DEFAULT NULL,
  `res_est_masquee` tinyint(1) NOT NULL DEFAULT '0',
  `res_ordre` smallint unsigned NOT NULL DEFAULT '1',
  `res_nb_consultations` int unsigned NOT NULL DEFAULT '0',
  `res_auteur_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`res_id`),
  KEY `n_ressources_res_as_id_foreign` (`res_as_id`),
  KEY `n_ressources_res_chapitre_id_foreign` (`res_chapitre_id`),
  KEY `n_ressources_res_groupe_id_foreign` (`res_groupe_id`),
  KEY `n_ressources_res_mode_id_foreign` (`res_mode_id`),
  KEY `n_ressources_res_fichier_id_foreign` (`res_fichier_id`),
  KEY `n_ressources_res_seance_id_foreign` (`res_seance_id`),
  KEY `n_ressources_res_auteur_id_foreign` (`res_auteur_id`),
  KEY `n_ressources_res_emo_id_res_as_id_index` (`res_emo_id`,`res_as_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_ressources_res_as_id_foreign` FOREIGN KEY (`res_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_ressources_res_auteur_id_foreign` FOREIGN KEY (`res_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_ressources_res_chapitre_id_foreign` FOREIGN KEY (`res_chapitre_id`) REFERENCES `n_ressource_chapitres` (`rch_id`) ON DELETE SET NULL,
  CONSTRAINT `n_ressources_res_emo_id_foreign` FOREIGN KEY (`res_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_ressources_res_fichier_id_foreign` FOREIGN KEY (`res_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_ressources_res_groupe_id_foreign` FOREIGN KEY (`res_groupe_id`) REFERENCES `n_groupes` (`grp_id`),
  CONSTRAINT `n_ressources_res_mode_id_foreign` FOREIGN KEY (`res_mode_id`) REFERENCES `n_modes_enseignement` (`mode_id`),
  CONSTRAINT `n_ressources_res_seance_id_foreign` FOREIGN KEY (`res_seance_id`) REFERENCES `n_seances` (`se_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultat_emo
DROP TABLE IF EXISTS `n_resultat_emo`;
CREATE TABLE `n_resultat_emo` (
  `rn_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rn_ins_id` bigint unsigned NOT NULL,
  `rn_emo_id` bigint unsigned NOT NULL,
  `rn_note_normale` decimal(5,2) DEFAULT NULL,
  `rn_note_cc` decimal(5,2) DEFAULT NULL,
  `rn_note_ep` decimal(5,2) DEFAULT NULL,
  `rn_note_et` decimal(5,2) DEFAULT NULL,
  `rn_rattrapage` decimal(5,2) DEFAULT NULL,
  `rn_moyenne_finale` decimal(5,2) DEFAULT NULL,
  `rn_substitution` decimal(5,2) DEFAULT NULL,
  `rn_substitution_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rn_substitution_par` bigint unsigned DEFAULT NULL,
  `rn_coef` decimal(5,2) NOT NULL DEFAULT '0.00',
  `rn_est_incomplet` tinyint(1) NOT NULL DEFAULT '0',
  `rn_est_convoque_rattrapage` tinyint(1) NOT NULL DEFAULT '0',
  `rn_rattrapage_exceptionnel_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `rn_absence_est_justifiee` tinyint(1) DEFAULT NULL,
  `rn_est_delibere` tinyint(1) NOT NULL DEFAULT '0',
  `rn_rattrapage_admin_est_visible` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rn_id`),
  UNIQUE KEY `uq_rn_ins_emo` (`rn_ins_id`,`rn_emo_id`),
  KEY `n_resultat_emo_rn_emo_id_foreign` (`rn_emo_id`),
  KEY `n_resultat_emo_created_by_foreign` (`created_by`),
  KEY `n_resultat_emo_updated_by_foreign` (`updated_by`),
  KEY `n_resultat_emo_rn_substitution_par_foreign` (`rn_substitution_par`),
  CONSTRAINT `n_resultat_emo_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_emo_rn_emo_id_foreign` FOREIGN KEY (`rn_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_resultat_emo_rn_ins_id_foreign` FOREIGN KEY (`rn_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_resultat_emo_rn_substitution_par_foreign` FOREIGN KEY (`rn_substitution_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_emo_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_rn_coef` CHECK ((`rn_coef` >= 0)),
  CONSTRAINT `chk_rn_notes` CHECK ((((`rn_note_normale` is null) or (`rn_note_normale` between 0 and 20)) and ((`rn_rattrapage` is null) or (`rn_rattrapage` between 0 and 20)) and ((`rn_moyenne_finale` is null) or (`rn_moyenne_finale` between 0 and 20)) and ((`rn_substitution` is null) or (`rn_substitution` between 0 and 20))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultat_examen
DROP TABLE IF EXISTS `n_resultat_examen`;
CREATE TABLE `n_resultat_examen` (
  `not_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `not_ins_id` bigint unsigned NOT NULL,
  `not_exam_id` bigint unsigned NOT NULL,
  `not_id_origine` bigint unsigned DEFAULT NULL,
  `not_statut` enum('P','D','T') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'P',
  `not_est_calcule` tinyint(1) NOT NULL DEFAULT '1',
  `not_statut_id` bigint unsigned DEFAULT NULL,
  `not_note` decimal(5,2) DEFAULT NULL,
  `not_est_absent` tinyint(1) NOT NULL DEFAULT '0',
  `not_modif_par` bigint unsigned DEFAULT NULL,
  `not_commentaire` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `not_active_ins_key` bigint unsigned GENERATED ALWAYS AS (if(((`not_est_calcule` = 1) and (`deleted_at` is null)),`not_ins_id`,NULL)) STORED,
  `not_active_exam_key` bigint unsigned GENERATED ALWAYS AS (if(((`not_est_calcule` = 1) and (`deleted_at` is null)),`not_exam_id`,NULL)) STORED,
  PRIMARY KEY (`not_id`),
  UNIQUE KEY `uq_not_active` (`not_active_ins_key`,`not_active_exam_key`),
  KEY `n_resultat_examen_not_ins_id_foreign` (`not_ins_id`),
  KEY `n_resultat_examen_not_id_origine_foreign` (`not_id_origine`),
  KEY `n_resultat_examen_not_statut_id_foreign` (`not_statut_id`),
  KEY `n_resultat_examen_not_modif_par_foreign` (`not_modif_par`),
  KEY `n_resultat_examen_not_exam_id_not_est_calcule_index` (`not_exam_id`,`not_est_calcule`),
  KEY `n_resultat_examen_created_by_foreign` (`created_by`),
  KEY `n_resultat_examen_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_resultat_examen_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_examen_not_exam_id_foreign` FOREIGN KEY (`not_exam_id`) REFERENCES `n_examens` (`exam_id`),
  CONSTRAINT `n_resultat_examen_not_id_origine_foreign` FOREIGN KEY (`not_id_origine`) REFERENCES `n_resultat_examen` (`not_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_examen_not_ins_id_foreign` FOREIGN KEY (`not_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_resultat_examen_not_modif_par_foreign` FOREIGN KEY (`not_modif_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_examen_not_statut_id_foreign` FOREIGN KEY (`not_statut_id`) REFERENCES `n_statut_notes` (`stn_id`),
  CONSTRAINT `n_resultat_examen_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_not_note` CHECK (((`not_note` is null) or (`not_note` between 0 and 20)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultat_uf
DROP TABLE IF EXISTS `n_resultat_uf`;
CREATE TABLE `n_resultat_uf` (
  `ru_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ru_ins_id` bigint unsigned NOT NULL,
  `ru_uf_id` bigint unsigned NOT NULL,
  `ru_note_cc` decimal(5,2) DEFAULT NULL,
  `ru_note_efcf_t` decimal(5,2) DEFAULT NULL,
  `ru_note_efcf_p` decimal(5,2) DEFAULT NULL,
  `ru_note` decimal(5,2) DEFAULT NULL,
  `ru_statut_id` bigint unsigned DEFAULT NULL,
  `ru_non_visibilite` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ru_id`),
  UNIQUE KEY `uq_ru` (`ru_ins_id`,`ru_uf_id`),
  KEY `n_resultat_uf_ru_uf_id_index` (`ru_uf_id`),
  KEY `n_resultat_uf_ru_statut_id_foreign` (`ru_statut_id`),
  KEY `n_resultat_uf_created_by_index` (`created_by`),
  CONSTRAINT `n_resultat_uf_ru_ins_id_foreign` FOREIGN KEY (`ru_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_resultat_uf_ru_statut_id_foreign` FOREIGN KEY (`ru_statut_id`) REFERENCES `n_statut_notes` (`stn_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultat_uf_ru_uf_id_foreign` FOREIGN KEY (`ru_uf_id`) REFERENCES `n_unites_formation` (`uf_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultats_admissions
DROP TABLE IF EXISTS `n_resultats_admissions`;
CREATE TABLE `n_resultats_admissions` (
  `ra_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ra_adm_id` bigint unsigned NOT NULL,
  `ra_moyenne_generale` decimal(5,2) DEFAULT NULL,
  `ra_moyenne_cc` decimal(5,2) DEFAULT NULL,
  `ra_moyenne_exam_theo` decimal(5,2) DEFAULT NULL,
  `ra_moyenne_exam_pratique` decimal(5,2) DEFAULT NULL,
  `ra_note_nsti` decimal(5,2) DEFAULT NULL,
  `ra_moyenne_finale` decimal(5,2) DEFAULT NULL,
  `ra_mention` enum('Passable','Assez Bien','Bien','Très Bien','Excellent') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ra_decision` enum('Admis','Ajourné') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Ajourné',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ra_id`),
  KEY `n_resultats_admissions_ra_adm_id_foreign` (`ra_adm_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_resultats_admissions_ra_adm_id_foreign` FOREIGN KEY (`ra_adm_id`) REFERENCES `n_admissions` (`adm_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultats_annuels
DROP TABLE IF EXISTS `n_resultats_annuels`;
CREATE TABLE `n_resultats_annuels` (
  `ra_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ra_ins_id` bigint unsigned NOT NULL,
  `ra_moyenne` decimal(5,2) DEFAULT NULL,
  `ra_mention` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ra_decision` enum('admis','non_admis') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ra_rang` smallint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `ra_note_cc` decimal(5,2) DEFAULT NULL,
  `ra_note_et` decimal(5,2) DEFAULT NULL,
  `ra_note_ep` decimal(5,2) DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ra_id`),
  UNIQUE KEY `n_resultats_annuels_ra_ins_id_unique` (`ra_ins_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_resultats_annuels_ra_ins_id_foreign` FOREIGN KEY (`ra_ins_id`) REFERENCES `n_inscriptions` (`ins_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_resultats_inscriptions
DROP TABLE IF EXISTS `n_resultats_inscriptions`;
CREATE TABLE `n_resultats_inscriptions` (
  `ri_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ri_ins_id` bigint unsigned NOT NULL,
  `ri_sem_id` bigint unsigned NOT NULL,
  `ri_note` decimal(5,2) DEFAULT NULL,
  `ri_note_cc` decimal(5,2) DEFAULT NULL,
  `ri_note_ep` decimal(5,2) DEFAULT NULL,
  `ri_note_et` decimal(5,2) DEFAULT NULL,
  `ri_note_ti` decimal(5,2) DEFAULT NULL,
  `ri_mention` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ri_decision` enum('admis','non_admis') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ri_motifs` json DEFAULT NULL,
  `ri_rang` smallint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ri_id`),
  UNIQUE KEY `uq_ri_ins_sem` (`ri_ins_id`,`ri_sem_id`),
  KEY `n_resultats_inscriptions_ri_sem_id_foreign` (`ri_sem_id`),
  KEY `n_resultats_inscriptions_created_by_foreign` (`created_by`),
  KEY `n_resultats_inscriptions_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_resultats_inscriptions_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_resultats_inscriptions_ri_ins_id_foreign` FOREIGN KEY (`ri_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_resultats_inscriptions_ri_sem_id_foreign` FOREIGN KEY (`ri_sem_id`) REFERENCES `n_semestres` (`sem_id`),
  CONSTRAINT `n_resultats_inscriptions_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_ri_note` CHECK (((`ri_note` is null) or (`ri_note` between 0 and 20)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_absences
DROP TABLE IF EXISTS `n_rh_absences`;
CREATE TABLE `n_rh_absences` (
  `abs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `abs_pers_id` bigint unsigned NOT NULL,
  `abs_type` enum('retard','absence_injustifiee','absence_justifiee','sortie_anticipee') COLLATE utf8mb4_unicode_ci NOT NULL,
  `abs_date` date NOT NULL,
  `abs_duree_minutes` smallint unsigned DEFAULT NULL,
  `abs_nb_jours` decimal(4,1) DEFAULT NULL,
  `abs_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `abs_fichier_id` bigint unsigned DEFAULT NULL,
  `abs_saisi_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`abs_id`),
  KEY `n_rh_absences_abs_fichier_id_foreign` (`abs_fichier_id`),
  KEY `n_rh_absences_abs_saisi_par_foreign` (`abs_saisi_par`),
  KEY `n_rh_absences_abs_pers_id_abs_date_index` (`abs_pers_id`,`abs_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_absences_abs_fichier_id_foreign` FOREIGN KEY (`abs_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_absences_abs_pers_id_foreign` FOREIGN KEY (`abs_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rh_absences_abs_saisi_par_foreign` FOREIGN KEY (`abs_saisi_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_attestations
DROP TABLE IF EXISTS `n_rh_attestations`;
CREATE TABLE `n_rh_attestations` (
  `att_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `att_pers_id` bigint unsigned NOT NULL,
  `att_type` enum('travail','salaire') COLLATE utf8mb4_unicode_ci NOT NULL,
  `att_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `att_statut` enum('demandee','delivree','refusee','annulee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'demandee',
  `att_demandee_par` bigint unsigned DEFAULT NULL,
  `att_traitee_par` bigint unsigned DEFAULT NULL,
  `att_traitee_le` timestamp NULL DEFAULT NULL,
  `att_motif_refus` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `att_reference` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `att_contenu` mediumtext COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`att_id`),
  UNIQUE KEY `n_rh_attestations_att_reference_unique` (`att_reference`),
  KEY `n_rh_attestations_att_pers_id_foreign` (`att_pers_id`),
  KEY `n_rh_attestations_att_demandee_par_foreign` (`att_demandee_par`),
  KEY `n_rh_attestations_att_traitee_par_foreign` (`att_traitee_par`),
  KEY `n_rh_attestations_att_statut_created_at_index` (`att_statut`,`created_at`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_attestations_att_demandee_par_foreign` FOREIGN KEY (`att_demandee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_attestations_att_pers_id_foreign` FOREIGN KEY (`att_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rh_attestations_att_traitee_par_foreign` FOREIGN KEY (`att_traitee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_avenants
DROP TABLE IF EXISTS `n_rh_avenants`;
CREATE TABLE `n_rh_avenants` (
  `av_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `av_ctr_id` bigint unsigned NOT NULL,
  `av_date_effet` date NOT NULL,
  `av_objet` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `av_avant` json NOT NULL,
  `av_apres` json NOT NULL,
  `av_fichier_id` bigint unsigned DEFAULT NULL,
  `av_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`av_id`),
  KEY `n_rh_avenants_av_ctr_id_foreign` (`av_ctr_id`),
  KEY `n_rh_avenants_av_fichier_id_foreign` (`av_fichier_id`),
  KEY `n_rh_avenants_av_cree_par_foreign` (`av_cree_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_avenants_av_cree_par_foreign` FOREIGN KEY (`av_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_avenants_av_ctr_id_foreign` FOREIGN KEY (`av_ctr_id`) REFERENCES `n_rh_contrats` (`ctr_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rh_avenants_av_fichier_id_foreign` FOREIGN KEY (`av_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_contrats
DROP TABLE IF EXISTS `n_rh_contrats`;
CREATE TABLE `n_rh_contrats` (
  `ctr_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ctr_pers_id` bigint unsigned NOT NULL,
  `ctr_type` enum('CDI','CDD','ANAPEC','STAGE','VACATION','AUTRE') COLLATE utf8mb4_unicode_ci NOT NULL,
  `ctr_reference` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ctr_date_debut` date NOT NULL,
  `ctr_date_fin` date DEFAULT NULL,
  `ctr_fin_periode_essai` date DEFAULT NULL,
  `ctr_salaire_brut` bigint unsigned DEFAULT NULL,
  `ctr_temps_travail` enum('plein','partiel') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'plein',
  `ctr_taux_temps` decimal(5,2) NOT NULL DEFAULT '100.00',
  `ctr_heures_hebdo` decimal(4,1) DEFAULT NULL,
  `ctr_poste_id` bigint unsigned DEFAULT NULL,
  `ctr_rompu_le` date DEFAULT NULL,
  `ctr_motif_fin` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ctr_fichier_id` bigint unsigned DEFAULT NULL,
  `ctr_commentaire` text COLLATE utf8mb4_unicode_ci,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`ctr_id`),
  KEY `n_rh_contrats_ctr_poste_id_foreign` (`ctr_poste_id`),
  KEY `n_rh_contrats_ctr_fichier_id_foreign` (`ctr_fichier_id`),
  KEY `n_rh_contrats_created_by_foreign` (`created_by`),
  KEY `n_rh_contrats_updated_by_foreign` (`updated_by`),
  KEY `n_rh_contrats_ctr_pers_id_ctr_date_debut_index` (`ctr_pers_id`,`ctr_date_debut`),
  KEY `n_rh_contrats_ctr_type_ctr_date_fin_index` (`ctr_type`,`ctr_date_fin`),
  CONSTRAINT `n_rh_contrats_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_contrats_ctr_fichier_id_foreign` FOREIGN KEY (`ctr_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_contrats_ctr_pers_id_foreign` FOREIGN KEY (`ctr_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rh_contrats_ctr_poste_id_foreign` FOREIGN KEY (`ctr_poste_id`) REFERENCES `n_rh_postes` (`pst_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_contrats_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_ctr_dates` CHECK (((`ctr_date_fin` is null) or (`ctr_date_fin` >= `ctr_date_debut`)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_demandes_conges
DROP TABLE IF EXISTS `n_rh_demandes_conges`;
CREATE TABLE `n_rh_demandes_conges` (
  `dc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dc_pers_id` bigint unsigned NOT NULL,
  `dc_type_id` bigint unsigned NOT NULL,
  `dc_date_debut` date NOT NULL,
  `dc_debut_apres_midi` tinyint(1) NOT NULL DEFAULT '0',
  `dc_date_fin` date NOT NULL,
  `dc_fin_midi` tinyint(1) NOT NULL DEFAULT '0',
  `dc_nb_jours` decimal(5,1) NOT NULL,
  `dc_annee` smallint unsigned NOT NULL,
  `dc_motif` text COLLATE utf8mb4_unicode_ci,
  `dc_justificatif_id` bigint unsigned DEFAULT NULL,
  `dc_statut` enum('en_attente_n1','en_attente_rh','approuvee','refusee','annulee') COLLATE utf8mb4_unicode_ci NOT NULL,
  `dc_cree_par` bigint unsigned DEFAULT NULL,
  `dc_n1_par` bigint unsigned DEFAULT NULL,
  `dc_n1_le` timestamp NULL DEFAULT NULL,
  `dc_n1_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dc_rh_par` bigint unsigned DEFAULT NULL,
  `dc_rh_le` timestamp NULL DEFAULT NULL,
  `dc_rh_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dc_motif_refus` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dc_annulee_par` bigint unsigned DEFAULT NULL,
  `dc_annulee_le` timestamp NULL DEFAULT NULL,
  `dc_motif_annulation` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dc_id`),
  KEY `n_rh_demandes_conges_dc_type_id_foreign` (`dc_type_id`),
  KEY `n_rh_demandes_conges_dc_justificatif_id_foreign` (`dc_justificatif_id`),
  KEY `n_rh_demandes_conges_dc_cree_par_foreign` (`dc_cree_par`),
  KEY `n_rh_demandes_conges_dc_n1_par_foreign` (`dc_n1_par`),
  KEY `n_rh_demandes_conges_dc_rh_par_foreign` (`dc_rh_par`),
  KEY `n_rh_demandes_conges_dc_annulee_par_foreign` (`dc_annulee_par`),
  KEY `n_rh_demandes_conges_dc_pers_id_dc_date_debut_dc_date_fin_index` (`dc_pers_id`,`dc_date_debut`,`dc_date_fin`),
  KEY `n_rh_demandes_conges_dc_statut_dc_date_debut_index` (`dc_statut`,`dc_date_debut`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_demandes_conges_dc_annulee_par_foreign` FOREIGN KEY (`dc_annulee_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_demandes_conges_dc_cree_par_foreign` FOREIGN KEY (`dc_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_demandes_conges_dc_justificatif_id_foreign` FOREIGN KEY (`dc_justificatif_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_demandes_conges_dc_n1_par_foreign` FOREIGN KEY (`dc_n1_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_demandes_conges_dc_pers_id_foreign` FOREIGN KEY (`dc_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rh_demandes_conges_dc_rh_par_foreign` FOREIGN KEY (`dc_rh_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_demandes_conges_dc_type_id_foreign` FOREIGN KEY (`dc_type_id`) REFERENCES `n_rh_types_conges` (`tcg_id`),
  CONSTRAINT `chk_dc_dates` CHECK ((`dc_date_fin` >= `dc_date_debut`))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_documents
DROP TABLE IF EXISTS `n_rh_documents`;
CREATE TABLE `n_rh_documents` (
  `doc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `doc_pers_id` bigint unsigned NOT NULL,
  `doc_type` enum('contrat','avenant','cin','diplome','cv','rib','certificat_medical','attestation','autre') COLLATE utf8mb4_unicode_ci NOT NULL,
  `doc_libelle` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
  `doc_fichier_id` bigint unsigned NOT NULL,
  `doc_date_expiration` date DEFAULT NULL,
  `doc_visible_employe` tinyint(1) NOT NULL DEFAULT '1',
  `doc_depose_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`doc_id`),
  KEY `n_rh_documents_doc_fichier_id_foreign` (`doc_fichier_id`),
  KEY `n_rh_documents_doc_depose_par_foreign` (`doc_depose_par`),
  KEY `n_rh_documents_doc_pers_id_doc_type_index` (`doc_pers_id`,`doc_type`),
  KEY `n_rh_documents_doc_date_expiration_index` (`doc_date_expiration`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_documents_doc_depose_par_foreign` FOREIGN KEY (`doc_depose_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_documents_doc_fichier_id_foreign` FOREIGN KEY (`doc_fichier_id`) REFERENCES `n_fichiers` (`fic_id`),
  CONSTRAINT `n_rh_documents_doc_pers_id_foreign` FOREIGN KEY (`doc_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_postes
DROP TABLE IF EXISTS `n_rh_postes`;
CREATE TABLE `n_rh_postes` (
  `pst_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pst_intitule` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `pst_service_id` bigint unsigned DEFAULT NULL,
  `pst_description` text COLLATE utf8mb4_unicode_ci,
  `pst_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`pst_id`),
  KEY `n_rh_postes_pst_service_id_foreign` (`pst_service_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_postes_pst_service_id_foreign` FOREIGN KEY (`pst_service_id`) REFERENCES `n_rh_services` (`svc_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_services
DROP TABLE IF EXISTS `n_rh_services`;
CREATE TABLE `n_rh_services` (
  `svc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `svc_centre_id` bigint unsigned DEFAULT NULL,
  `svc_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `svc_nom` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
  `svc_responsable_id` bigint unsigned DEFAULT NULL,
  `svc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`svc_id`),
  UNIQUE KEY `n_rh_services_svc_centre_id_svc_nom_unique` (`svc_centre_id`,`svc_nom`),
  KEY `n_rh_services_svc_responsable_id_foreign` (`svc_responsable_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_services_svc_centre_id_foreign` FOREIGN KEY (`svc_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_rh_services_svc_responsable_id_foreign` FOREIGN KEY (`svc_responsable_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_soldes_conges
DROP TABLE IF EXISTS `n_rh_soldes_conges`;
CREATE TABLE `n_rh_soldes_conges` (
  `sld_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sld_pers_id` bigint unsigned NOT NULL,
  `sld_annee` smallint unsigned NOT NULL,
  `sld_report` decimal(5,1) DEFAULT NULL,
  `sld_ajustement` decimal(5,1) NOT NULL DEFAULT '0.0',
  `sld_commentaire` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sld_modifie_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sld_id`),
  UNIQUE KEY `n_rh_soldes_conges_sld_pers_id_sld_annee_unique` (`sld_pers_id`,`sld_annee`),
  KEY `n_rh_soldes_conges_sld_modifie_par_foreign` (`sld_modifie_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rh_soldes_conges_sld_modifie_par_foreign` FOREIGN KEY (`sld_modifie_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_rh_soldes_conges_sld_pers_id_foreign` FOREIGN KEY (`sld_pers_id`) REFERENCES `n_personnel` (`pers_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rh_types_conges
DROP TABLE IF EXISTS `n_rh_types_conges`;
CREATE TABLE `n_rh_types_conges` (
  `tcg_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tcg_code` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `tcg_libelle` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
  `tcg_categorie` enum('annuel','maladie','maternite','paternite','exceptionnel','sans_solde','recuperation') COLLATE utf8mb4_unicode_ci NOT NULL,
  `tcg_decompte_solde` tinyint(1) NOT NULL DEFAULT '0',
  `tcg_justificatif_requis` tinyint(1) NOT NULL DEFAULT '0',
  `tcg_remunere` tinyint(1) NOT NULL DEFAULT '1',
  `tcg_jours_calendaires` tinyint(1) NOT NULL DEFAULT '0',
  `tcg_jours_max` decimal(5,1) DEFAULT NULL,
  `tcg_couleur` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tcg_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tcg_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tcg_id`),
  UNIQUE KEY `n_rh_types_conges_tcg_code_unique` (`tcg_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_role_permissions
DROP TABLE IF EXISTS `n_role_permissions`;
CREATE TABLE `n_role_permissions` (
  `rp_role_id` bigint unsigned NOT NULL,
  `rp_perm_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rp_role_id`,`rp_perm_id`),
  KEY `n_role_permissions_rp_perm_id_foreign` (`rp_perm_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_role_permissions_rp_perm_id_foreign` FOREIGN KEY (`rp_perm_id`) REFERENCES `n_permissions` (`perm_id`) ON DELETE CASCADE,
  CONSTRAINT `n_role_permissions_rp_role_id_foreign` FOREIGN KEY (`rp_role_id`) REFERENCES `n_roles` (`role_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_roles
DROP TABLE IF EXISTS `n_roles`;
CREATE TABLE `n_roles` (
  `role_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `role_code` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `role_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `role_espace` enum('administration','enseignant','etudiant','candidat','tuteur') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'administration',
  `role_est_systeme` tinyint(1) NOT NULL DEFAULT '0',
  `role_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`role_id`),
  UNIQUE KEY `n_roles_role_code_unique` (`role_code`),
  UNIQUE KEY `n_roles_role_nom_unique` (`role_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_rubriques_budgetaires
DROP TABLE IF EXISTS `n_rubriques_budgetaires`;
CREATE TABLE `n_rubriques_budgetaires` (
  `rb_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `rb_budget_id` bigint unsigned NOT NULL,
  `rb_parent_id` bigint unsigned DEFAULT NULL,
  `rb_libelle` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rb_type` enum('recette','depense') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `rb_prevision` decimal(12,2) NOT NULL DEFAULT '0.00',
  `rb_source` enum('encaissements','vacations') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`rb_id`),
  UNIQUE KEY `uq_rubriques_budgetaire_budget_parent_libell` (`rb_budget_id`,`rb_parent_id`,`rb_libelle`),
  KEY `n_rubriques_budgetaires_rb_parent_id_foreign` (`rb_parent_id`),
  KEY `n_rubriques_budgetaires_rb_budget_id_rb_type_index` (`rb_budget_id`,`rb_type`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_rubriques_budgetaires_rb_budget_id_foreign` FOREIGN KEY (`rb_budget_id`) REFERENCES `n_budgets` (`bud_id`) ON DELETE CASCADE,
  CONSTRAINT `n_rubriques_budgetaires_rb_parent_id_foreign` FOREIGN KEY (`rb_parent_id`) REFERENCES `n_rubriques_budgetaires` (`rb_id`),
  CONSTRAINT `chk_rb_prevision` CHECK ((`rb_prevision` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_salles
DROP TABLE IF EXISTS `n_salles`;
CREATE TABLE `n_salles` (
  `salle_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `salle_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `salle_emplacement` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `salle_equipements` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `salle_capacite` smallint unsigned NOT NULL,
  `salle_site_id` bigint unsigned NOT NULL,
  `salle_type_id` bigint unsigned NOT NULL,
  `salle_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`salle_id`),
  UNIQUE KEY `n_salles_salle_site_id_salle_nom_unique` (`salle_site_id`,`salle_nom`),
  KEY `n_salles_salle_type_id_foreign` (`salle_type_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_salles_salle_site_id_foreign` FOREIGN KEY (`salle_site_id`) REFERENCES `n_sites` (`site_id`),
  CONSTRAINT `n_salles_salle_type_id_foreign` FOREIGN KEY (`salle_type_id`) REFERENCES `n_types_salles` (`ts_id`),
  CONSTRAINT `chk_salle_capacite` CHECK ((`salle_capacite` > 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_salles_unites
DROP TABLE IF EXISTS `n_salles_unites`;
CREATE TABLE `n_salles_unites` (
  `sl_un_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sl_un_unite_id` bigint unsigned NOT NULL,
  `sl_un_salle_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sl_un_id`),
  UNIQUE KEY `n_salles_unites_sl_un_unite_id_sl_un_salle_id_unique` (`sl_un_unite_id`,`sl_un_salle_id`),
  KEY `n_salles_unites_sl_un_salle_id_foreign` (`sl_un_salle_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_salles_unites_sl_un_salle_id_foreign` FOREIGN KEY (`sl_un_salle_id`) REFERENCES `n_salles` (`salle_id`),
  CONSTRAINT `n_salles_unites_sl_un_unite_id_foreign` FOREIGN KEY (`sl_un_unite_id`) REFERENCES `n_edt_unites` (`uet_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_seance_log
DROP TABLE IF EXISTS `n_seance_log`;
CREATE TABLE `n_seance_log` (
  `sl_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sl_se_id` bigint unsigned NOT NULL,
  `sl_contenu` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sl_user_id` bigint unsigned DEFAULT NULL,
  `sl_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sl_id`),
  KEY `n_seance_log_sl_user_id_foreign` (`sl_user_id`),
  KEY `n_seance_log_sl_se_id_sl_date_index` (`sl_se_id`,`sl_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_seance_log_sl_se_id_foreign` FOREIGN KEY (`sl_se_id`) REFERENCES `n_seances` (`se_id`) ON DELETE CASCADE,
  CONSTRAINT `n_seance_log_sl_user_id_foreign` FOREIGN KEY (`sl_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_seances
DROP TABLE IF EXISTS `n_seances`;
CREATE TABLE `n_seances` (
  `se_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `se_uet_id` bigint unsigned DEFAULT NULL,
  `se_edt_id` bigint unsigned DEFAULT NULL,
  `se_emo_id` bigint unsigned NOT NULL,
  `se_type_edt_id` bigint unsigned NOT NULL,
  `se_prof_id` bigint unsigned NOT NULL,
  `se_prof_bkp_id` bigint unsigned DEFAULT NULL,
  `se_groupe_id` bigint unsigned DEFAULT NULL,
  `se_salle_id` bigint unsigned DEFAULT NULL,
  `se_est_en_ligne` tinyint(1) NOT NULL DEFAULT '0',
  `se_lien_visio` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `se_date` date NOT NULL,
  `se_hdeb` time NOT NULL,
  `se_hfin` time NOT NULL,
  `se_duree_min` smallint unsigned GENERATED ALWAYS AS (((time_to_sec(`se_hfin`) - time_to_sec(`se_hdeb`)) DIV 60)) STORED,
  `se_duree_realisee_min` smallint unsigned DEFAULT NULL,
  `se_nom` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `se_statut_id` bigint unsigned NOT NULL,
  `se_est_prof_absent` tinyint(1) NOT NULL DEFAULT '0',
  `se_type` enum('N','D','F') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'N',
  `se_date_origine` date DEFAULT NULL,
  `se_source_id` bigint unsigned DEFAULT NULL,
  `se_cahier_text` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `se_appel_le` timestamp NULL DEFAULT NULL,
  `se_appel_par` bigint unsigned DEFAULT NULL,
  `se_remarque` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `se_unite_key` bigint unsigned GENERATED ALWAYS AS (if((`deleted_at` is null),`se_uet_id`,NULL)) STORED,
  PRIMARY KEY (`se_id`),
  UNIQUE KEY `uq_se_unite_date` (`se_unite_key`,`se_date`,`se_hdeb`),
  KEY `n_seances_se_uet_id_foreign` (`se_uet_id`),
  KEY `n_seances_se_edt_id_foreign` (`se_edt_id`),
  KEY `n_seances_se_emo_id_foreign` (`se_emo_id`),
  KEY `n_seances_se_type_edt_id_foreign` (`se_type_edt_id`),
  KEY `n_seances_se_groupe_id_foreign` (`se_groupe_id`),
  KEY `n_seances_se_salle_id_foreign` (`se_salle_id`),
  KEY `n_seances_se_statut_id_foreign` (`se_statut_id`),
  KEY `n_seances_se_date_se_hdeb_index` (`se_date`,`se_hdeb`),
  KEY `n_seances_se_prof_id_se_date_index` (`se_prof_id`,`se_date`),
  KEY `n_seances_se_prof_bkp_id_se_date_index` (`se_prof_bkp_id`,`se_date`),
  KEY `n_seances_created_by_foreign` (`created_by`),
  KEY `n_seances_updated_by_foreign` (`updated_by`),
  KEY `n_seances_se_source_id_foreign` (`se_source_id`),
  KEY `n_seances_se_appel_par_foreign` (`se_appel_par`),
  KEY `n_seances_se_edt_id_se_date_index` (`se_edt_id`,`se_date`),
  CONSTRAINT `n_seances_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_seances_se_appel_par_foreign` FOREIGN KEY (`se_appel_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_seances_se_edt_id_foreign` FOREIGN KEY (`se_edt_id`) REFERENCES `n_edt` (`edt_id`),
  CONSTRAINT `n_seances_se_emo_id_foreign` FOREIGN KEY (`se_emo_id`) REFERENCES `n_elements_modules` (`emo_id`),
  CONSTRAINT `n_seances_se_groupe_id_foreign` FOREIGN KEY (`se_groupe_id`) REFERENCES `n_groupes` (`grp_id`) ON DELETE SET NULL,
  CONSTRAINT `n_seances_se_prof_bkp_id_foreign` FOREIGN KEY (`se_prof_bkp_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_seances_se_prof_id_foreign` FOREIGN KEY (`se_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_seances_se_salle_id_foreign` FOREIGN KEY (`se_salle_id`) REFERENCES `n_salles` (`salle_id`),
  CONSTRAINT `n_seances_se_source_id_foreign` FOREIGN KEY (`se_source_id`) REFERENCES `n_seances` (`se_id`) ON DELETE SET NULL,
  CONSTRAINT `n_seances_se_statut_id_foreign` FOREIGN KEY (`se_statut_id`) REFERENCES `n_statuts_seances` (`ss_id`),
  CONSTRAINT `n_seances_se_type_edt_id_foreign` FOREIGN KEY (`se_type_edt_id`) REFERENCES `n_type_edt` (`edtype_id`),
  CONSTRAINT `n_seances_se_uet_id_foreign` FOREIGN KEY (`se_uet_id`) REFERENCES `n_edt_unites` (`uet_id`),
  CONSTRAINT `n_seances_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_se_date_origine` CHECK (((`se_date_origine` is null) or (`se_type` = 'D'))),
  CONSTRAINT `chk_se_heures` CHECK ((`se_hfin` > `se_hdeb`)),
  CONSTRAINT `chk_se_rattachement` CHECK (((`se_uet_id` is not null) or (`se_edt_id` is not null)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_seances_salles
DROP TABLE IF EXISTS `n_seances_salles`;
CREATE TABLE `n_seances_salles` (
  `sts_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sts_se_id` bigint unsigned NOT NULL,
  `sts_salle_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sts_id`),
  UNIQUE KEY `n_seances_salles_sts_se_id_sts_salle_id_unique` (`sts_se_id`,`sts_salle_id`),
  KEY `n_seances_salles_sts_salle_id_index` (`sts_salle_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_seances_salles_sts_salle_id_foreign` FOREIGN KEY (`sts_salle_id`) REFERENCES `n_salles` (`salle_id`),
  CONSTRAINT `n_seances_salles_sts_se_id_foreign` FOREIGN KEY (`sts_se_id`) REFERENCES `n_seances` (`se_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_semestres
DROP TABLE IF EXISTS `n_semestres`;
CREATE TABLE `n_semestres` (
  `sem_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sem_code` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sem_nom` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sem_session_id` bigint unsigned NOT NULL,
  `sem_niveau_filiere` tinyint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sem_id`),
  UNIQUE KEY `uq_sem_niveau_session` (`sem_niveau_filiere`,`sem_session_id`),
  UNIQUE KEY `n_semestres_sem_code_unique` (`sem_code`),
  KEY `n_semestres_sem_session_id_foreign` (`sem_session_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_semestres_sem_session_id_foreign` FOREIGN KEY (`sem_session_id`) REFERENCES `n_session` (`sess_id`),
  CONSTRAINT `chk_sem_niveau` CHECK ((`sem_niveau_filiere` between 1 and 10))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_sequences
DROP TABLE IF EXISTS `n_sequences`;
CREATE TABLE `n_sequences` (
  `seq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `seq_type` enum('P','A','I','M','R','V') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `seq_as_id` bigint unsigned DEFAULT NULL,
  `seq_centre_id` bigint unsigned DEFAULT NULL,
  `seq_valeur` int unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `seq_as_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`seq_as_id`,0)) STORED,
  `seq_centre_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`seq_centre_id`,0)) STORED,
  PRIMARY KEY (`seq_id`),
  UNIQUE KEY `uq_sequence` (`seq_type`,`seq_as_key`,`seq_centre_key`),
  KEY `n_sequences_seq_as_id_foreign` (`seq_as_id`),
  KEY `n_sequences_seq_centre_id_foreign` (`seq_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_sequences_seq_as_id_foreign` FOREIGN KEY (`seq_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_sequences_seq_centre_id_foreign` FOREIGN KEY (`seq_centre_id`) REFERENCES `n_centres` (`ct_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_sequences_pedagogiques
DROP TABLE IF EXISTS `n_sequences_pedagogiques`;
CREATE TABLE `n_sequences_pedagogiques` (
  `seq_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `seq_emo_id` bigint unsigned NOT NULL,
  `seq_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `seq_titre` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
  `seq_objectif_inter` text COLLATE utf8mb4_unicode_ci,
  `seq_duree` decimal(5,2) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`seq_id`),
  KEY `n_sequences_pedagogiques_seq_emo_id_foreign` (`seq_emo_id`),
  KEY `n_sequences_pedagogiques_created_by_index` (`created_by`),
  CONSTRAINT `n_sequences_pedagogiques_seq_emo_id_foreign` FOREIGN KEY (`seq_emo_id`) REFERENCES `n_elements_modules` (`emo_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_series_bac
DROP TABLE IF EXISTS `n_series_bac`;
CREATE TABLE `n_series_bac` (
  `sb_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sb_type_bac_id` bigint unsigned NOT NULL,
  `sb_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sb_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sb_id`),
  UNIQUE KEY `n_series_bac_sb_type_bac_id_sb_nom_unique` (`sb_type_bac_id`,`sb_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_series_bac_sb_type_bac_id_foreign` FOREIGN KEY (`sb_type_bac_id`) REFERENCES `n_types_bac` (`tb_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_session
DROP TABLE IF EXISTS `n_session`;
CREATE TABLE `n_session` (
  `sess_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sess_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sess_id`),
  UNIQUE KEY `n_session_sess_nom_unique` (`sess_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_sites
DROP TABLE IF EXISTS `n_sites`;
CREATE TABLE `n_sites` (
  `site_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `site_centre_id` bigint unsigned NOT NULL,
  `site_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `site_nom` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `site_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `site_ville_id` bigint unsigned DEFAULT NULL,
  `site_est_principal` tinyint(1) NOT NULL DEFAULT '0',
  `site_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `site_principal_key` bigint unsigned GENERATED ALWAYS AS (if((`site_est_principal` = 1),`site_centre_id`,NULL)) STORED,
  PRIMARY KEY (`site_id`),
  UNIQUE KEY `n_sites_site_centre_id_site_nom_unique` (`site_centre_id`,`site_nom`),
  UNIQUE KEY `uq_site_centre` (`site_id`,`site_centre_id`),
  UNIQUE KEY `n_sites_site_code_unique` (`site_code`),
  UNIQUE KEY `uq_site_principal` (`site_principal_key`),
  KEY `n_sites_site_ville_id_foreign` (`site_ville_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_sites_site_centre_id_foreign` FOREIGN KEY (`site_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_sites_site_ville_id_foreign` FOREIGN KEY (`site_ville_id`) REFERENCES `n_villes` (`vil_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_soutenance_jury
DROP TABLE IF EXISTS `n_soutenance_jury`;
CREATE TABLE `n_soutenance_jury` (
  `sj_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sj_sout_id` bigint unsigned NOT NULL,
  `sj_role` enum('president','rapporteur','encadrant','externe') COLLATE utf8mb4_unicode_ci NOT NULL,
  `sj_prof_id` bigint unsigned DEFAULT NULL,
  `sj_nom` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sj_qualite` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sj_email` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sj_id`),
  UNIQUE KEY `n_soutenance_jury_sj_sout_id_sj_role_unique` (`sj_sout_id`,`sj_role`),
  KEY `n_soutenance_jury_sj_prof_id_index` (`sj_prof_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_soutenance_jury_sj_prof_id_foreign` FOREIGN KEY (`sj_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_soutenance_jury_sj_sout_id_foreign` FOREIGN KEY (`sj_sout_id`) REFERENCES `n_soutenances` (`sout_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_soutenances
DROP TABLE IF EXISTS `n_soutenances`;
CREATE TABLE `n_soutenances` (
  `sout_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sout_stg_id` bigint unsigned NOT NULL,
  `sout_date` date NOT NULL,
  `sout_hdeb` time NOT NULL,
  `sout_hfin` time NOT NULL,
  `sout_salle_id` bigint unsigned DEFAULT NULL,
  `sout_lieu` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sout_statut` enum('planifiee','realisee','annulee') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'planifiee',
  `sout_convoque_le` timestamp NULL DEFAULT NULL,
  `sout_note_rapport` decimal(5,2) DEFAULT NULL,
  `sout_note_oral` decimal(5,2) DEFAULT NULL,
  `sout_note_entreprise` decimal(5,2) DEFAULT NULL,
  `sout_poids_rapport` tinyint unsigned DEFAULT NULL,
  `sout_poids_oral` tinyint unsigned DEFAULT NULL,
  `sout_poids_entreprise` tinyint unsigned DEFAULT NULL,
  `sout_note_finale` decimal(5,2) DEFAULT NULL,
  `sout_mention` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sout_observations` text COLLATE utf8mb4_unicode_ci,
  `sout_pv_valide_le` timestamp NULL DEFAULT NULL,
  `sout_pv_valide_par` bigint unsigned DEFAULT NULL,
  `sout_exam_id` bigint unsigned DEFAULT NULL,
  `sout_note_reportee_le` timestamp NULL DEFAULT NULL,
  `sout_cree_par` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sout_id`),
  UNIQUE KEY `n_soutenances_sout_stg_id_unique` (`sout_stg_id`),
  KEY `n_soutenances_sout_salle_id_foreign` (`sout_salle_id`),
  KEY `n_soutenances_sout_pv_valide_par_foreign` (`sout_pv_valide_par`),
  KEY `n_soutenances_sout_exam_id_foreign` (`sout_exam_id`),
  KEY `n_soutenances_sout_cree_par_foreign` (`sout_cree_par`),
  KEY `n_soutenances_sout_date_sout_statut_index` (`sout_date`,`sout_statut`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_soutenances_sout_cree_par_foreign` FOREIGN KEY (`sout_cree_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_soutenances_sout_exam_id_foreign` FOREIGN KEY (`sout_exam_id`) REFERENCES `n_examens` (`exam_id`) ON DELETE SET NULL,
  CONSTRAINT `n_soutenances_sout_pv_valide_par_foreign` FOREIGN KEY (`sout_pv_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_soutenances_sout_salle_id_foreign` FOREIGN KEY (`sout_salle_id`) REFERENCES `n_salles` (`salle_id`) ON DELETE SET NULL,
  CONSTRAINT `n_soutenances_sout_stg_id_foreign` FOREIGN KEY (`sout_stg_id`) REFERENCES `n_stages` (`stg_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_sout_heures` CHECK ((`sout_hfin` > `sout_hdeb`)),
  CONSTRAINT `chk_sout_notes` CHECK ((((`sout_note_rapport` is null) or (`sout_note_rapport` between 0 and 20)) and ((`sout_note_oral` is null) or (`sout_note_oral` between 0 and 20)) and ((`sout_note_entreprise` is null) or (`sout_note_entreprise` between 0 and 20)) and ((`sout_note_finale` is null) or (`sout_note_finale` between 0 and 20))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_stage_suivis
DROP TABLE IF EXISTS `n_stage_suivis`;
CREATE TABLE `n_stage_suivis` (
  `ssu_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ssu_stg_id` bigint unsigned NOT NULL,
  `ssu_type` enum('note','visite','entretien','appel') COLLATE utf8mb4_unicode_ci NOT NULL,
  `ssu_date` date NOT NULL,
  `ssu_contenu` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `ssu_auteur_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ssu_id`),
  KEY `n_stage_suivis_ssu_auteur_id_foreign` (`ssu_auteur_id`),
  KEY `n_stage_suivis_ssu_stg_id_ssu_date_index` (`ssu_stg_id`,`ssu_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_stage_suivis_ssu_auteur_id_foreign` FOREIGN KEY (`ssu_auteur_id`) REFERENCES `n_utilisateurs` (`user_id`),
  CONSTRAINT `n_stage_suivis_ssu_stg_id_foreign` FOREIGN KEY (`ssu_stg_id`) REFERENCES `n_stages` (`stg_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_stages
DROP TABLE IF EXISTS `n_stages`;
CREATE TABLE `n_stages` (
  `stg_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stg_ins_id` bigint unsigned NOT NULL,
  `stg_ent_id` bigint unsigned NOT NULL,
  `stg_dem_id` bigint unsigned DEFAULT NULL,
  `stg_origine` enum('administration','etudiant','offre') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'administration',
  `stg_offre_id` bigint unsigned DEFAULT NULL,
  `stg_type` enum('initiation','technique','pfa','pfe','autre') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stg_sujet` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stg_description` text COLLATE utf8mb4_unicode_ci,
  `stg_date_debut` date NOT NULL,
  `stg_date_fin` date NOT NULL,
  `stg_tuteur_entreprise_nom` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stg_tuteur_entreprise_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stg_tuteur_entreprise_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stg_contact_id` bigint unsigned DEFAULT NULL,
  `stg_encadrant_prof_id` bigint unsigned DEFAULT NULL,
  `stg_statut` enum('demande','valide','convention_generee','convention_signee','en_cours','termine','evalue','annule','refuse') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'demande',
  `stg_motif` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stg_valide_le` timestamp NULL DEFAULT NULL,
  `stg_valide_par` bigint unsigned DEFAULT NULL,
  `stg_convention_fichier_id` bigint unsigned DEFAULT NULL,
  `stg_convention_dd_id` bigint unsigned DEFAULT NULL,
  `stg_convention_signee_le` timestamp NULL DEFAULT NULL,
  `stg_attestation_dd_id` bigint unsigned DEFAULT NULL,
  `stg_rapport_fichier_id` bigint unsigned DEFAULT NULL,
  `stg_rapport_limite` date DEFAULT NULL,
  `stg_rapport_depose_le` timestamp NULL DEFAULT NULL,
  `stg_rapport_final_fichier_id` bigint unsigned DEFAULT NULL,
  `stg_rapport_final_depose_le` timestamp NULL DEFAULT NULL,
  `stg_rapport_en_retard` tinyint(1) NOT NULL DEFAULT '0',
  `stg_eval_encadrant_note` decimal(5,2) DEFAULT NULL,
  `stg_eval_encadrant_commentaire` text COLLATE utf8mb4_unicode_ci,
  `stg_eval_encadrant_le` timestamp NULL DEFAULT NULL,
  `stg_eval_tuteur_criteres` json DEFAULT NULL,
  `stg_eval_tuteur_note` decimal(5,2) DEFAULT NULL,
  `stg_eval_tuteur_commentaire` text COLLATE utf8mb4_unicode_ci,
  `stg_eval_tuteur_le` timestamp NULL DEFAULT NULL,
  `stg_eval_tuteur_par` bigint unsigned DEFAULT NULL,
  `stg_note` decimal(5,2) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`stg_id`),
  KEY `n_stages_stg_ent_id_foreign` (`stg_ent_id`),
  KEY `n_stages_stg_dem_id_foreign` (`stg_dem_id`),
  KEY `n_stages_stg_encadrant_prof_id_foreign` (`stg_encadrant_prof_id`),
  KEY `n_stages_stg_convention_fichier_id_foreign` (`stg_convention_fichier_id`),
  KEY `n_stages_stg_rapport_fichier_id_foreign` (`stg_rapport_fichier_id`),
  KEY `n_stages_stg_ins_id_stg_statut_index` (`stg_ins_id`,`stg_statut`),
  KEY `n_stages_created_by_foreign` (`created_by`),
  KEY `n_stages_updated_by_foreign` (`updated_by`),
  KEY `n_stages_stg_offre_id_foreign` (`stg_offre_id`),
  KEY `n_stages_stg_contact_id_foreign` (`stg_contact_id`),
  KEY `n_stages_stg_valide_par_foreign` (`stg_valide_par`),
  KEY `n_stages_stg_convention_dd_id_foreign` (`stg_convention_dd_id`),
  KEY `n_stages_stg_attestation_dd_id_foreign` (`stg_attestation_dd_id`),
  KEY `n_stages_stg_rapport_final_fichier_id_foreign` (`stg_rapport_final_fichier_id`),
  KEY `n_stages_stg_eval_tuteur_par_foreign` (`stg_eval_tuteur_par`),
  KEY `n_stages_stg_type_stg_statut_index` (`stg_type`,`stg_statut`),
  CONSTRAINT `n_stages_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_attestation_dd_id_foreign` FOREIGN KEY (`stg_attestation_dd_id`) REFERENCES `n_documents_delivres` (`dd_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_contact_id_foreign` FOREIGN KEY (`stg_contact_id`) REFERENCES `n_entreprise_contacts` (`ec_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_convention_dd_id_foreign` FOREIGN KEY (`stg_convention_dd_id`) REFERENCES `n_documents_delivres` (`dd_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_convention_fichier_id_foreign` FOREIGN KEY (`stg_convention_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_dem_id_foreign` FOREIGN KEY (`stg_dem_id`) REFERENCES `n_demandes` (`dem_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_encadrant_prof_id_foreign` FOREIGN KEY (`stg_encadrant_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_ent_id_foreign` FOREIGN KEY (`stg_ent_id`) REFERENCES `n_entreprises` (`ent_id`),
  CONSTRAINT `n_stages_stg_eval_tuteur_par_foreign` FOREIGN KEY (`stg_eval_tuteur_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_ins_id_foreign` FOREIGN KEY (`stg_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_stages_stg_offre_id_foreign` FOREIGN KEY (`stg_offre_id`) REFERENCES `n_offres_stage` (`off_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_rapport_fichier_id_foreign` FOREIGN KEY (`stg_rapport_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_rapport_final_fichier_id_foreign` FOREIGN KEY (`stg_rapport_final_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_stg_valide_par_foreign` FOREIGN KEY (`stg_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_stages_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_stg_dates` CHECK ((`stg_date_fin` >= `stg_date_debut`)),
  CONSTRAINT `chk_stg_eval_notes` CHECK ((((`stg_eval_encadrant_note` is null) or (`stg_eval_encadrant_note` between 0 and 20)) and ((`stg_eval_tuteur_note` is null) or (`stg_eval_tuteur_note` between 0 and 20)))),
  CONSTRAINT `chk_stg_note` CHECK (((`stg_note` is null) or (`stg_note` between 0 and 20)))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statut_notes
DROP TABLE IF EXISTS `n_statut_notes`;
CREATE TABLE `n_statut_notes` (
  `stn_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stn_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stn_code` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stn_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `stn_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`stn_id`),
  UNIQUE KEY `n_statut_notes_stn_code_unique` (`stn_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_admissions
DROP TABLE IF EXISTS `n_statuts_admissions`;
CREATE TABLE `n_statuts_admissions` (
  `sa_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sa_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sa_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sa_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sa_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `sa_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sa_id`),
  UNIQUE KEY `n_statuts_admissions_sa_code_unique` (`sa_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_criteres
DROP TABLE IF EXISTS `n_statuts_criteres`;
CREATE TABLE `n_statuts_criteres` (
  `sc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `sc_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sc_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sc_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sc_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `sc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`sc_id`),
  UNIQUE KEY `n_statuts_criteres_sc_code_unique` (`sc_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_demandes
DROP TABLE IF EXISTS `n_statuts_demandes`;
CREATE TABLE `n_statuts_demandes` (
  `ds_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ds_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ds_nom` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ds_classe_css` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ds_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `ds_est_final` tinyint(1) NOT NULL DEFAULT '0',
  `ds_glpi_statut` tinyint unsigned DEFAULT NULL,
  `ds_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ds_id`),
  UNIQUE KEY `n_statuts_demandes_ds_code_unique` (`ds_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_inscriptions
DROP TABLE IF EXISTS `n_statuts_inscriptions`;
CREATE TABLE `n_statuts_inscriptions` (
  `si_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `si_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `si_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `si_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `si_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `si_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`si_id`),
  UNIQUE KEY `n_statuts_inscriptions_si_code_unique` (`si_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_prospect
DROP TABLE IF EXISTS `n_statuts_prospect`;
CREATE TABLE `n_statuts_prospect` (
  `stp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `stp_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stp_libelle` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `stp_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stp_ordre` tinyint unsigned NOT NULL,
  `stp_necessite_motif` tinyint(1) NOT NULL DEFAULT '0',
  `stp_est_final` tinyint(1) NOT NULL DEFAULT '0',
  `stp_est_automatique` tinyint(1) NOT NULL DEFAULT '0',
  `stp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`stp_id`),
  UNIQUE KEY `n_statuts_prospect_stp_code_unique` (`stp_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_statuts_seances
DROP TABLE IF EXISTS `n_statuts_seances`;
CREATE TABLE `n_statuts_seances` (
  `ss_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ss_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ss_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ss_couleur` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ss_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `ss_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ss_id`),
  UNIQUE KEY `n_statuts_seances_ss_code_unique` (`ss_code`),
  UNIQUE KEY `n_statuts_seances_ss_nom_unique` (`ss_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_tags
DROP TABLE IF EXISTS `n_tags`;
CREATE TABLE `n_tags` (
  `tag_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tag_nom` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tag_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tag_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tag_id`),
  UNIQUE KEY `n_tags_tag_nom_unique` (`tag_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_themes
DROP TABLE IF EXISTS `n_themes`;
CREATE TABLE `n_themes` (
  `thm_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `thm_centre_id` bigint unsigned DEFAULT NULL,
  `thm_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_primaire` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_secondaire` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_accent` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_fond` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_surface` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_texte` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_texte_secondaire` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_bordure` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_menu_fond` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_menu_texte` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_entete_fond` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_entete_texte` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_succes` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_avertissement` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_erreur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_couleur_info` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `thm_police` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Inter',
  `thm_arrondi_px` tinyint unsigned NOT NULL DEFAULT '8',
  `thm_mode_sombre_autorise` tinyint(1) NOT NULL DEFAULT '1',
  `thm_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `thm_centre_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`thm_centre_id`,0)) VIRTUAL,
  PRIMARY KEY (`thm_id`),
  UNIQUE KEY `uq_theme_centre` (`thm_centre_key`),
  KEY `n_themes_thm_centre_id_foreign` (`thm_centre_id`),
  KEY `n_themes_created_by_foreign` (`created_by`),
  KEY `n_themes_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_themes_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_themes_thm_centre_id_foreign` FOREIGN KEY (`thm_centre_id`) REFERENCES `n_centres` (`ct_id`) ON DELETE CASCADE,
  CONSTRAINT `n_themes_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_thm_accent` CHECK (`thm_couleur_accent` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_arrondi` CHECK ((`thm_arrondi_px` <= 32)),
  CONSTRAINT `chk_thm_avertissement` CHECK (`thm_couleur_avertissement` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_bordure` CHECK (`thm_couleur_bordure` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_entete_fond` CHECK (`thm_couleur_entete_fond` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_entete_texte` CHECK (`thm_couleur_entete_texte` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_erreur` CHECK (`thm_couleur_erreur` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_fond` CHECK (`thm_couleur_fond` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_info` CHECK (`thm_couleur_info` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_menu_fond` CHECK (`thm_couleur_menu_fond` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_menu_texte` CHECK (`thm_couleur_menu_texte` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_primaire` CHECK (`thm_couleur_primaire` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_secondaire` CHECK (`thm_couleur_secondaire` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_succes` CHECK (`thm_couleur_succes` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_surface` CHECK (`thm_couleur_surface` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_texte` CHECK (`thm_couleur_texte` REGEXP '^#[0-9A-Fa-f]{6}$'),
  CONSTRAINT `chk_thm_texte_secondaire` CHECK (`thm_couleur_texte_secondaire` REGEXP '^#[0-9A-Fa-f]{6}$')
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_transaction_echeances
DROP TABLE IF EXISTS `n_transaction_echeances`;
CREATE TABLE `n_transaction_echeances` (
  `tre_tp_id` bigint unsigned NOT NULL,
  `tre_pcv_id` bigint unsigned NOT NULL,
  `tre_montant` decimal(12,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tre_tp_id`,`tre_pcv_id`),
  KEY `n_transaction_echeances_tre_pcv_id_foreign` (`tre_pcv_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_transaction_echeances_tre_pcv_id_foreign` FOREIGN KEY (`tre_pcv_id`) REFERENCES `n_periodes_convenues` (`pcv_id`),
  CONSTRAINT `n_transaction_echeances_tre_tp_id_foreign` FOREIGN KEY (`tre_tp_id`) REFERENCES `n_transactions_paiement` (`trp_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_tre_montant` CHECK ((`tre_montant` > 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_transactions_paiement
DROP TABLE IF EXISTS `n_transactions_paiement`;
CREATE TABLE `n_transactions_paiement` (
  `trp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `trp_reference` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trp_ins_id` bigint unsigned NOT NULL,
  `trp_user_id` bigint unsigned DEFAULT NULL,
  `trp_passerelle` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trp_montant` decimal(12,2) NOT NULL,
  `trp_devise` char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'MAD',
  `trp_statut` enum('initiee','en_cours','reussie','echouee','annulee','remboursee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'initiee',
  `trp_reference_banque` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `trp_code_retour` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `trp_reponse_brute` json DEFAULT NULL,
  `trp_rec_id` bigint unsigned DEFAULT NULL,
  `trp_payee_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`trp_id`),
  UNIQUE KEY `n_transactions_paiement_trp_reference_unique` (`trp_reference`),
  UNIQUE KEY `n_transactions_paiement_trp_reference_banque_unique` (`trp_reference_banque`),
  UNIQUE KEY `n_transactions_paiement_trp_rec_id_unique` (`trp_rec_id`),
  KEY `n_transactions_paiement_trp_user_id_foreign` (`trp_user_id`),
  KEY `n_transactions_paiement_trp_ins_id_trp_statut_index` (`trp_ins_id`,`trp_statut`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_transactions_paiement_trp_ins_id_foreign` FOREIGN KEY (`trp_ins_id`) REFERENCES `n_inscriptions` (`ins_id`),
  CONSTRAINT `n_transactions_paiement_trp_rec_id_foreign` FOREIGN KEY (`trp_rec_id`) REFERENCES `n_recus` (`rec_id`) ON DELETE SET NULL,
  CONSTRAINT `n_transactions_paiement_trp_user_id_foreign` FOREIGN KEY (`trp_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_trp_montant` CHECK ((`trp_montant` > 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_transitions_demande
DROP TABLE IF EXISTS `n_transitions_demande`;
CREATE TABLE `n_transitions_demande` (
  `td_de_id` bigint unsigned NOT NULL,
  `td_vers_id` bigint unsigned NOT NULL,
  `td_permission_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `td_motif_obligatoire` tinyint(1) NOT NULL DEFAULT '0',
  `td_notifie_etudiant` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`td_de_id`,`td_vers_id`),
  KEY `n_transitions_demande_td_vers_id_foreign` (`td_vers_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_transitions_demande_td_de_id_foreign` FOREIGN KEY (`td_de_id`) REFERENCES `n_statuts_demandes` (`ds_id`) ON DELETE CASCADE,
  CONSTRAINT `n_transitions_demande_td_vers_id_foreign` FOREIGN KEY (`td_vers_id`) REFERENCES `n_statuts_demandes` (`ds_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_transitions_inscription
DROP TABLE IF EXISTS `n_transitions_inscription`;
CREATE TABLE `n_transitions_inscription` (
  `ti_de_id` bigint unsigned NOT NULL,
  `ti_vers_id` bigint unsigned NOT NULL,
  `ti_permission_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ti_motif_obligatoire` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ti_de_id`,`ti_vers_id`),
  KEY `n_transitions_inscription_ti_vers_id_foreign` (`ti_vers_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_transitions_inscription_ti_de_id_foreign` FOREIGN KEY (`ti_de_id`) REFERENCES `n_statuts_inscriptions` (`si_id`) ON DELETE CASCADE,
  CONSTRAINT `n_transitions_inscription_ti_vers_id_foreign` FOREIGN KEY (`ti_vers_id`) REFERENCES `n_statuts_inscriptions` (`si_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_transitions_prospect
DROP TABLE IF EXISTS `n_transitions_prospect`;
CREATE TABLE `n_transitions_prospect` (
  `tp_de_id` bigint unsigned NOT NULL,
  `tp_vers_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tp_de_id`,`tp_vers_id`),
  KEY `n_transitions_prospect_tp_vers_id_foreign` (`tp_vers_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_transitions_prospect_tp_de_id_foreign` FOREIGN KEY (`tp_de_id`) REFERENCES `n_statuts_prospect` (`stp_id`) ON DELETE CASCADE,
  CONSTRAINT `n_transitions_prospect_tp_vers_id_foreign` FOREIGN KEY (`tp_vers_id`) REFERENCES `n_statuts_prospect` (`stp_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_tuteur_etudiants
DROP TABLE IF EXISTS `n_tuteur_etudiants`;
CREATE TABLE `n_tuteur_etudiants` (
  `te_tut_id` bigint unsigned NOT NULL,
  `te_etud_id` bigint unsigned NOT NULL,
  `te_lien_parente_id` bigint unsigned NOT NULL,
  `te_est_contact_principal` tinyint(1) NOT NULL DEFAULT '0',
  `te_est_responsable_financier` tinyint(1) NOT NULL DEFAULT '0',
  `te_est_contact_urgence` tinyint(1) NOT NULL DEFAULT '0',
  `te_peut_consulter` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `te_principal_key` bigint unsigned GENERATED ALWAYS AS (if((`te_est_contact_principal` = 1),`te_etud_id`,NULL)) VIRTUAL,
  PRIMARY KEY (`te_tut_id`,`te_etud_id`),
  UNIQUE KEY `uq_te_principal` (`te_principal_key`),
  KEY `n_tuteur_etudiants_te_etud_id_foreign` (`te_etud_id`),
  KEY `n_tuteur_etudiants_te_lien_parente_id_foreign` (`te_lien_parente_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_tuteur_etudiants_te_etud_id_foreign` FOREIGN KEY (`te_etud_id`) REFERENCES `n_etudiants` (`etud_id`) ON DELETE CASCADE,
  CONSTRAINT `n_tuteur_etudiants_te_lien_parente_id_foreign` FOREIGN KEY (`te_lien_parente_id`) REFERENCES `n_liens_parente` (`lp_id`),
  CONSTRAINT `n_tuteur_etudiants_te_tut_id_foreign` FOREIGN KEY (`te_tut_id`) REFERENCES `n_tuteurs` (`tut_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_tuteurs
DROP TABLE IF EXISTS `n_tuteurs`;
CREATE TABLE `n_tuteurs` (
  `tut_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tut_civilite` enum('M','MME','MLLE') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tut_prenom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tut_cin` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_passeport` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_tel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tut_tel2` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_adresse` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_ville_id` bigint unsigned DEFAULT NULL,
  `tut_profession` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tut_user_id` bigint unsigned DEFAULT NULL,
  `tut_compte_invite_le` timestamp NULL DEFAULT NULL,
  `tut_compte_invite_par` bigint unsigned DEFAULT NULL,
  `tut_compte_desactive_le` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tut_id`),
  UNIQUE KEY `n_tuteurs_tut_cin_unique` (`tut_cin`),
  UNIQUE KEY `n_tuteurs_tut_passeport_unique` (`tut_passeport`),
  UNIQUE KEY `n_tuteurs_tut_user_id_unique` (`tut_user_id`),
  KEY `n_tuteurs_tut_ville_id_foreign` (`tut_ville_id`),
  KEY `n_tuteurs_tut_nom_tut_prenom_index` (`tut_nom`,`tut_prenom`),
  KEY `n_tuteurs_created_by_foreign` (`created_by`),
  KEY `n_tuteurs_updated_by_foreign` (`updated_by`),
  KEY `n_tuteurs_tut_compte_invite_par_foreign` (`tut_compte_invite_par`),
  KEY `n_tuteurs_tut_email_index` (`tut_email`),
  CONSTRAINT `n_tuteurs_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_tuteurs_tut_compte_invite_par_foreign` FOREIGN KEY (`tut_compte_invite_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_tuteurs_tut_user_id_foreign` FOREIGN KEY (`tut_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_tuteurs_tut_ville_id_foreign` FOREIGN KEY (`tut_ville_id`) REFERENCES `n_villes` (`vil_id`),
  CONSTRAINT `n_tuteurs_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_type_edt
DROP TABLE IF EXISTS `n_type_edt`;
CREATE TABLE `n_type_edt` (
  `edtype_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `edtype_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `edtype_type_exam_id` bigint unsigned DEFAULT NULL,
  `edtype_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `edtype_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `edtype_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `edtype_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`edtype_id`),
  UNIQUE KEY `n_type_edt_edtype_nom_unique` (`edtype_nom`),
  UNIQUE KEY `n_type_edt_edtype_code_unique` (`edtype_code`),
  KEY `n_type_edt_edtype_type_exam_id_foreign` (`edtype_type_exam_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_type_edt_edtype_type_exam_id_foreign` FOREIGN KEY (`edtype_type_exam_id`) REFERENCES `n_types_examens` (`tpe_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_bac
DROP TABLE IF EXISTS `n_types_bac`;
CREATE TABLE `n_types_bac` (
  `tb_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tb_nom` varchar(70) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tb_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `tb_ordre` tinyint unsigned DEFAULT NULL,
  `tb_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tb_id`),
  UNIQUE KEY `n_types_bac_tb_nom_unique` (`tb_nom`),
  UNIQUE KEY `n_types_bac_tb_code_unique` (`tb_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_contrats
DROP TABLE IF EXISTS `n_types_contrats`;
CREATE TABLE `n_types_contrats` (
  `tpc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tpc_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpc_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpc_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tpc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tpc_id`),
  UNIQUE KEY `n_types_contrats_tpc_code_unique` (`tpc_code`),
  UNIQUE KEY `n_types_contrats_tpc_nom_unique` (`tpc_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_demandes
DROP TABLE IF EXISTS `n_types_demandes`;
CREATE TABLE `n_types_demandes` (
  `tdem_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tdem_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tdem_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tdem_cible` enum('E','P','T') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'T',
  `tdem_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tdem_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tdem_id`),
  UNIQUE KEY `n_types_demandes_tdem_code_unique` (`tdem_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_details_calenders
DROP TABLE IF EXISTS `n_types_details_calenders`;
CREATE TABLE `n_types_details_calenders` (
  `dc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `dc_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dc_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `dc_type_edt_id` bigint unsigned DEFAULT NULL,
  `dc_couleur` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '#9aa5b1',
  `dc_categorie` enum('ENSEIGNEMENT','EVALUATION','INTERRUPTION','EVENEMENT','INFO') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EVENEMENT',
  `dc_bloque_cours` tinyint(1) NOT NULL DEFAULT '0',
  `dc_est_exclusif` tinyint(1) NOT NULL DEFAULT '1',
  `dc_priorite` tinyint unsigned NOT NULL DEFAULT '50',
  `dc_portee` enum('NIVEAU','GLOBAL') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'NIVEAU',
  `dc_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `dc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`dc_id`),
  UNIQUE KEY `n_types_details_calenders_dc_code_unique` (`dc_code`),
  KEY `n_types_details_calenders_dc_type_edt_id_foreign` (`dc_type_edt_id`),
  KEY `n_types_details_calenders_dc_est_actif_dc_ordre_index` (`dc_est_actif`,`dc_ordre`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_types_details_calenders_dc_type_edt_id_foreign` FOREIGN KEY (`dc_type_edt_id`) REFERENCES `n_type_edt` (`edtype_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_diplomes_acces
DROP TABLE IF EXISTS `n_types_diplomes_acces`;
CREATE TABLE `n_types_diplomes_acces` (
  `tda_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tda_nom` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tda_niveau_apresbac` tinyint unsigned NOT NULL DEFAULT '0',
  `tda_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tda_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tda_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tda_id`),
  UNIQUE KEY `n_types_diplomes_acces_tda_nom_unique` (`tda_nom`),
  UNIQUE KEY `n_types_diplomes_acces_tda_code_unique` (`tda_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_documents
DROP TABLE IF EXISTS `n_types_documents`;
CREATE TABLE `n_types_documents` (
  `tdoc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tdoc_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tdoc_est_public` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `tdoc_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tdoc_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tdoc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tdoc_id`),
  UNIQUE KEY `n_types_documents_tdoc_nom_unique` (`tdoc_nom`),
  UNIQUE KEY `n_types_documents_tdoc_code_unique` (`tdoc_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_examens
DROP TABLE IF EXISTS `n_types_examens`;
CREATE TABLE `n_types_examens` (
  `tpe_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tpe_abbr` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpe_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpe_coef` decimal(5,2) NOT NULL DEFAULT '0.00',
  `tpe_est_rattrapage` tinyint(1) NOT NULL DEFAULT '0',
  `tpe_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tpe_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tpe_id`),
  UNIQUE KEY `n_types_examens_tpe_abbr_unique` (`tpe_abbr`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `chk_tpe_coef` CHECK ((`tpe_coef` between 0 and 1))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_frais
DROP TABLE IF EXISTS `n_types_frais`;
CREATE TABLE `n_types_frais` (
  `tpf_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tpf_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpf_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpf_ordre` tinyint unsigned NOT NULL DEFAULT '0',
  `tpf_tp_defaut_id` bigint unsigned DEFAULT NULL,
  `tpf_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tpf_id`),
  UNIQUE KEY `n_types_frais_tpf_code_unique` (`tpf_code`),
  UNIQUE KEY `n_types_frais_tpf_nom_unique` (`tpf_nom`),
  KEY `n_types_frais_tpf_tp_defaut_id_foreign` (`tpf_tp_defaut_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_types_frais_tpf_tp_defaut_id_foreign` FOREIGN KEY (`tpf_tp_defaut_id`) REFERENCES `n_types_periodes_frais` (`tp_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_periodes_frais
DROP TABLE IF EXISTS `n_types_periodes_frais`;
CREATE TABLE `n_types_periodes_frais` (
  `tp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tp_code` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tp_nom` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tp_nb_periodes` tinyint unsigned NOT NULL,
  `tp_frequence_mois` tinyint unsigned DEFAULT NULL,
  `tp_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tp_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tp_id`),
  UNIQUE KEY `n_types_periodes_frais_tp_code_unique` (`tp_code`),
  UNIQUE KEY `n_types_periodes_frais_tp_nom_unique` (`tp_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `chk_tp_nb` CHECK ((`tp_nb_periodes` between 1 and 12))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_pieces
DROP TABLE IF EXISTS `n_types_pieces`;
CREATE TABLE `n_types_pieces` (
  `tpc_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tpc_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpc_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tpc_mp_id` bigint unsigned NOT NULL,
  `tpc_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tpc_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tpc_id`),
  UNIQUE KEY `n_types_pieces_tpc_code_unique` (`tpc_code`),
  UNIQUE KEY `n_types_pieces_tpc_nom_unique` (`tpc_nom`),
  KEY `n_types_pieces_tpc_mp_id_foreign` (`tpc_mp_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_types_pieces_tpc_mp_id_foreign` FOREIGN KEY (`tpc_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_reclamation
DROP TABLE IF EXISTS `n_types_reclamation`;
CREATE TABLE `n_types_reclamation` (
  `trec_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `trec_ref` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `trec_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trec_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `trec_cible` enum('E','P','T') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'T',
  `trec_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`trec_id`),
  UNIQUE KEY `n_types_reclamation_trec_ref_unique` (`trec_ref`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_reductions
DROP TABLE IF EXISTS `n_types_reductions`;
CREATE TABLE `n_types_reductions` (
  `tred_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tred_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tred_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tred_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `tred_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `tred_description` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tred_typefrais_id` bigint unsigned DEFAULT NULL,
  `tred_mode` enum('P','M') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'P',
  `tred_valeur_defaut` decimal(12,2) DEFAULT NULL,
  `tred_valeur_max` decimal(12,2) DEFAULT NULL,
  `tred_est_cumulable` tinyint(1) NOT NULL DEFAULT '1',
  `tred_justificatif_requis` tinyint(1) NOT NULL DEFAULT '0',
  `tred_date_debut` date DEFAULT NULL,
  `tred_date_fin` date DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`tred_id`),
  UNIQUE KEY `n_types_reductions_tred_code_unique` (`tred_code`),
  KEY `n_types_reductions_tred_typefrais_id_foreign` (`tred_typefrais_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_types_reductions_tred_typefrais_id_foreign` FOREIGN KEY (`tred_typefrais_id`) REFERENCES `n_types_frais` (`tpf_id`),
  CONSTRAINT `chk_tred_dates` CHECK (((`tred_date_debut` is null) or (`tred_date_fin` is null) or (`tred_date_fin` >= `tred_date_debut`))),
  CONSTRAINT `chk_tred_valeurs` CHECK ((((`tred_valeur_defaut` is null) or (`tred_valeur_defaut` >= 0)) and ((`tred_valeur_max` is null) or (`tred_valeur_max` >= 0)) and ((`tred_mode` = 'M') or (((`tred_valeur_max` is null) or (`tred_valeur_max` <= 100)) and ((`tred_valeur_defaut` is null) or (`tred_valeur_defaut` <= 100))))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_remarques
DROP TABLE IF EXISTS `n_types_remarques`;
CREATE TABLE `n_types_remarques` (
  `trem_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `trem_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trem_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trem_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `trem_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`trem_id`),
  UNIQUE KEY `n_types_remarques_trem_nom_unique` (`trem_nom`),
  UNIQUE KEY `n_types_remarques_trem_code_unique` (`trem_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_types_salles
DROP TABLE IF EXISTS `n_types_salles`;
CREATE TABLE `n_types_salles` (
  `ts_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ts_nom` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ts_code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `ts_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `ts_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ts_id`),
  UNIQUE KEY `n_types_salles_ts_nom_unique` (`ts_nom`),
  UNIQUE KEY `n_types_salles_ts_code_unique` (`ts_code`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_unites_formation
DROP TABLE IF EXISTS `n_unites_formation`;
CREATE TABLE `n_unites_formation` (
  `uf_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uf_classe_id` bigint unsigned NOT NULL,
  `uf_sem_id` bigint unsigned DEFAULT NULL,
  `uf_mat_id` bigint unsigned NOT NULL,
  `uf_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uf_index` int NOT NULL DEFAULT '0',
  `uf_domaine_id` bigint unsigned DEFAULT NULL,
  `uf_coef` decimal(20,2) NOT NULL DEFAULT '0.00',
  `uf_type` enum('MOD','U.F','PFE','PFA','Stage','TI') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'U.F',
  `uf_objectif_general` varchar(400) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `uf_responsable_prof_id` bigint unsigned DEFAULT NULL,
  `uf_visible_pv` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`uf_id`),
  KEY `idx_uf_classe_sem` (`uf_classe_id`,`uf_sem_id`),
  KEY `n_unites_formation_uf_sem_id_foreign` (`uf_sem_id`),
  KEY `n_unites_formation_uf_mat_id_foreign` (`uf_mat_id`),
  KEY `n_unites_formation_uf_responsable_prof_id_foreign` (`uf_responsable_prof_id`),
  KEY `n_unites_formation_created_by_index` (`created_by`),
  KEY `n_unites_formation_uf_domaine_id_foreign` (`uf_domaine_id`),
  CONSTRAINT `n_unites_formation_uf_classe_id_foreign` FOREIGN KEY (`uf_classe_id`) REFERENCES `n_classes` (`classe_id`),
  CONSTRAINT `n_unites_formation_uf_domaine_id_foreign` FOREIGN KEY (`uf_domaine_id`) REFERENCES `n_domaines_uf` (`duf_id`) ON DELETE SET NULL,
  CONSTRAINT `n_unites_formation_uf_mat_id_foreign` FOREIGN KEY (`uf_mat_id`) REFERENCES `n_matieres` (`mat_id`),
  CONSTRAINT `n_unites_formation_uf_responsable_prof_id_foreign` FOREIGN KEY (`uf_responsable_prof_id`) REFERENCES `n_enseignants` (`prof_id`) ON DELETE SET NULL,
  CONSTRAINT `n_unites_formation_uf_sem_id_foreign` FOREIGN KEY (`uf_sem_id`) REFERENCES `n_semestres` (`sem_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_utilisateur_perimetres
DROP TABLE IF EXISTS `n_utilisateur_perimetres`;
CREATE TABLE `n_utilisateur_perimetres` (
  `up_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `up_user_id` bigint unsigned NOT NULL,
  `up_centre_id` bigint unsigned NOT NULL,
  `up_site_id` bigint unsigned DEFAULT NULL,
  `up_est_defaut` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  `up_site_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`up_site_id`,0)) STORED,
  `up_defaut_key` bigint unsigned GENERATED ALWAYS AS (if((`up_est_defaut` = 1),`up_user_id`,NULL)) VIRTUAL,
  PRIMARY KEY (`up_id`),
  UNIQUE KEY `uq_up_perimetre` (`up_user_id`,`up_centre_id`,`up_site_key`),
  UNIQUE KEY `uq_up_defaut` (`up_defaut_key`),
  KEY `n_utilisateur_perimetres_up_centre_id_foreign` (`up_centre_id`),
  KEY `fk_up_site_centre` (`up_site_id`,`up_centre_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `fk_up_site_centre` FOREIGN KEY (`up_site_id`, `up_centre_id`) REFERENCES `n_sites` (`site_id`, `site_centre_id`),
  CONSTRAINT `n_utilisateur_perimetres_up_centre_id_foreign` FOREIGN KEY (`up_centre_id`) REFERENCES `n_centres` (`ct_id`),
  CONSTRAINT `n_utilisateur_perimetres_up_user_id_foreign` FOREIGN KEY (`up_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_utilisateur_roles
DROP TABLE IF EXISTS `n_utilisateur_roles`;
CREATE TABLE `n_utilisateur_roles` (
  `ur_user_id` bigint unsigned NOT NULL,
  `ur_role_id` bigint unsigned NOT NULL,
  `ur_attribue_par` bigint unsigned DEFAULT NULL,
  `ur_attribue_le` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`ur_user_id`,`ur_role_id`),
  KEY `n_utilisateur_roles_ur_role_id_foreign` (`ur_role_id`),
  KEY `n_utilisateur_roles_ur_attribue_par_foreign` (`ur_attribue_par`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_utilisateur_roles_ur_attribue_par_foreign` FOREIGN KEY (`ur_attribue_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_utilisateur_roles_ur_role_id_foreign` FOREIGN KEY (`ur_role_id`) REFERENCES `n_roles` (`role_id`),
  CONSTRAINT `n_utilisateur_roles_ur_user_id_foreign` FOREIGN KEY (`ur_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_utilisateurs
DROP TABLE IF EXISTS `n_utilisateurs`;
CREATE TABLE `n_utilisateurs` (
  `user_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_nom_affiche` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `user_email_verifie_le` timestamp NULL DEFAULT NULL,
  `user_reglement_accepte_le` timestamp NULL DEFAULT NULL,
  `user_derniere_connexion` timestamp NULL DEFAULT NULL,
  `user_tentatives_echouees` tinyint unsigned NOT NULL DEFAULT '0',
  `user_bloque_jusqu_a` timestamp NULL DEFAULT NULL,
  `user_mdp_modifie_le` timestamp NULL DEFAULT NULL,
  `user_doit_changer_mdp` tinyint(1) NOT NULL DEFAULT '0',
  `user_utilise_app_mobile` tinyint(1) NOT NULL DEFAULT '0',
  `remember_token` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE KEY `n_utilisateurs_user_email_unique` (`user_email`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_vacation_paiements
DROP TABLE IF EXISTS `n_vacation_paiements`;
CREATE TABLE `n_vacation_paiements` (
  `vp_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vp_vacation_id` bigint unsigned NOT NULL,
  `vp_numero` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `vp_date` date NOT NULL,
  `vp_type` enum('IR','COMPLEMENT') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `vp_mp_id` bigint unsigned NOT NULL,
  `vp_piece_id` bigint unsigned DEFAULT NULL,
  `vp_taux_heure` decimal(10,2) DEFAULT NULL,
  `vp_nombre_heure` decimal(6,2) DEFAULT NULL,
  `vp_montant_brut` decimal(12,2) NOT NULL DEFAULT '0.00',
  `vp_montant_igr` decimal(12,2) DEFAULT NULL,
  `vp_montant_complement` decimal(12,2) DEFAULT NULL,
  `vp_montant` decimal(12,2) NOT NULL,
  `vp_commentaire` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`vp_id`),
  UNIQUE KEY `n_vacation_paiements_vp_numero_unique` (`vp_numero`),
  KEY `n_vacation_paiements_vp_vacation_id_foreign` (`vp_vacation_id`),
  KEY `n_vacation_paiements_vp_piece_id_index` (`vp_piece_id`),
  KEY `n_vacation_paiements_vp_mp_id_foreign` (`vp_mp_id`),
  KEY `n_vacation_paiements_created_by_foreign` (`created_by`),
  KEY `n_vacation_paiements_updated_by_foreign` (`updated_by`),
  CONSTRAINT `n_vacation_paiements_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_vacation_paiements_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_vacation_paiements_vp_mp_id_foreign` FOREIGN KEY (`vp_mp_id`) REFERENCES `n_modes_paiement` (`mp_id`),
  CONSTRAINT `n_vacation_paiements_vp_piece_id_foreign` FOREIGN KEY (`vp_piece_id`) REFERENCES `n_pieces` (`pc_id`),
  CONSTRAINT `n_vacation_paiements_vp_vacation_id_foreign` FOREIGN KEY (`vp_vacation_id`) REFERENCES `n_vacations` (`vac_id`),
  CONSTRAINT `chk_vp_montants` CHECK (((`vp_montant_brut` >= 0) and (`vp_montant` >= 0) and ((`vp_montant_igr` is null) or (`vp_montant_igr` >= 0)) and ((`vp_montant_complement` is null) or (`vp_montant_complement` >= 0)) and ((`vp_taux_heure` is null) or (`vp_taux_heure` >= 0)) and ((`vp_nombre_heure` is null) or (`vp_nombre_heure` >= 0)))),
  CONSTRAINT `chk_vp_net` CHECK ((`vp_montant` = ((`vp_montant_brut` - coalesce(`vp_montant_igr`,0)) + coalesce(`vp_montant_complement`,0)))),
  CONSTRAINT `chk_vp_type` CHECK ((((`vp_type` = 'IR') and (`vp_montant_complement` is null)) or ((`vp_type` = 'COMPLEMENT') and (`vp_montant_igr` is null))))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_vacation_seances
DROP TABLE IF EXISTS `n_vacation_seances`;
CREATE TABLE `n_vacation_seances` (
  `vs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vs_vacation_id` bigint unsigned NOT NULL,
  `vs_seance_id` bigint unsigned NOT NULL,
  `vs_nb_heures` decimal(5,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`vs_id`),
  UNIQUE KEY `n_vacation_seances_vs_seance_id_unique` (`vs_seance_id`),
  KEY `n_vacation_seances_vs_vacation_id_foreign` (`vs_vacation_id`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_vacation_seances_vs_seance_id_foreign` FOREIGN KEY (`vs_seance_id`) REFERENCES `n_seances` (`se_id`),
  CONSTRAINT `n_vacation_seances_vs_vacation_id_foreign` FOREIGN KEY (`vs_vacation_id`) REFERENCES `n_vacations` (`vac_id`) ON DELETE CASCADE,
  CONSTRAINT `chk_vs_nb_heures` CHECK ((`vs_nb_heures` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_vacation_statue
DROP TABLE IF EXISTS `n_vacation_statue`;
CREATE TABLE `n_vacation_statue` (
  `vs_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vs_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `vs_nom` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `vs_couleur` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `vs_ordre` smallint unsigned NOT NULL DEFAULT '0',
  `vs_est_actif` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`vs_id`),
  UNIQUE KEY `n_vacation_statue_vs_code_unique` (`vs_code`),
  UNIQUE KEY `n_vacation_statue_vs_nom_unique` (`vs_nom`),
  KEY `idx_created_by` (`created_by`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_vacations
DROP TABLE IF EXISTS `n_vacations`;
CREATE TABLE `n_vacations` (
  `vac_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vac_as_id` bigint unsigned NOT NULL,
  `vac_prof_id` bigint unsigned NOT NULL,
  `vac_mois` tinyint unsigned NOT NULL,
  `vac_heures` decimal(7,2) NOT NULL DEFAULT '0.00',
  `vac_taux_horaire` decimal(10,2) DEFAULT NULL,
  `vac_montant` decimal(12,2) NOT NULL DEFAULT '0.00',
  `vac_ir_brut` decimal(12,2) NOT NULL DEFAULT '0.00',
  `vac_igr` decimal(12,2) NOT NULL DEFAULT '0.00',
  `vac_especes` decimal(12,2) NOT NULL DEFAULT '0.00',
  `vac_vs_id` bigint unsigned NOT NULL,
  `vac_valide_par` bigint unsigned DEFAULT NULL,
  `vac_valide_le` timestamp NULL DEFAULT NULL,
  `vac_commentaire` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `vac_prof_key` bigint unsigned GENERATED ALWAYS AS (if((`deleted_at` is null),`vac_prof_id`,NULL)) STORED,
  PRIMARY KEY (`vac_id`),
  UNIQUE KEY `uq_vac_prof_mois` (`vac_prof_key`,`vac_as_id`,`vac_mois`),
  KEY `n_vacations_vac_prof_id_foreign` (`vac_prof_id`),
  KEY `n_vacations_vac_vs_id_foreign` (`vac_vs_id`),
  KEY `n_vacations_vac_as_id_vac_mois_index` (`vac_as_id`,`vac_mois`),
  KEY `n_vacations_created_by_foreign` (`created_by`),
  KEY `n_vacations_updated_by_foreign` (`updated_by`),
  KEY `n_vacations_vac_valide_par_foreign` (`vac_valide_par`),
  CONSTRAINT `n_vacations_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_vacations_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_vacations_vac_as_id_foreign` FOREIGN KEY (`vac_as_id`) REFERENCES `n_annees_scolaires` (`as_id`),
  CONSTRAINT `n_vacations_vac_prof_id_foreign` FOREIGN KEY (`vac_prof_id`) REFERENCES `n_enseignants` (`prof_id`),
  CONSTRAINT `n_vacations_vac_valide_par_foreign` FOREIGN KEY (`vac_valide_par`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `n_vacations_vac_vs_id_foreign` FOREIGN KEY (`vac_vs_id`) REFERENCES `n_vacation_statue` (`vs_id`),
  CONSTRAINT `chk_vac_mois` CHECK ((`vac_mois` between 1 and 12)),
  CONSTRAINT `chk_vac_montant` CHECK ((`vac_montant` >= 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_versements_banque
DROP TABLE IF EXISTS `n_versements_banque`;
CREATE TABLE `n_versements_banque` (
  `vb_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vb_caisse_id` bigint unsigned NOT NULL,
  `vb_cs_id` bigint unsigned NOT NULL,
  `vb_date` date NOT NULL,
  `vb_montant` decimal(12,2) NOT NULL,
  `vb_reference` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `vb_fichier_id` bigint unsigned DEFAULT NULL,
  `vb_user_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`vb_id`),
  KEY `n_versements_banque_vb_cs_id_foreign` (`vb_cs_id`),
  KEY `n_versements_banque_vb_fichier_id_foreign` (`vb_fichier_id`),
  KEY `n_versements_banque_vb_user_id_foreign` (`vb_user_id`),
  KEY `n_versements_banque_vb_caisse_id_vb_date_index` (`vb_caisse_id`,`vb_date`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_versements_banque_vb_caisse_id_foreign` FOREIGN KEY (`vb_caisse_id`) REFERENCES `n_caisse` (`caisse_id`),
  CONSTRAINT `n_versements_banque_vb_cs_id_foreign` FOREIGN KEY (`vb_cs_id`) REFERENCES `n_comptes_societe` (`cs_id`),
  CONSTRAINT `n_versements_banque_vb_fichier_id_foreign` FOREIGN KEY (`vb_fichier_id`) REFERENCES `n_fichiers` (`fic_id`) ON DELETE SET NULL,
  CONSTRAINT `n_versements_banque_vb_user_id_foreign` FOREIGN KEY (`vb_user_id`) REFERENCES `n_utilisateurs` (`user_id`) ON DELETE SET NULL,
  CONSTRAINT `chk_vb_montant` CHECK ((`vb_montant` > 0))
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table n_villes
DROP TABLE IF EXISTS `n_villes`;
CREATE TABLE `n_villes` (
  `vil_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `vil_nom` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `vil_nom_ar` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `vil_pays_id` bigint unsigned NOT NULL,
  `vil_est_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `created_by` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`vil_id`),
  UNIQUE KEY `n_villes_vil_pays_id_vil_nom_unique` (`vil_pays_id`,`vil_nom`),
  KEY `idx_created_by` (`created_by`),
  CONSTRAINT `n_villes_vil_pays_id_foreign` FOREIGN KEY (`vil_pays_id`) REFERENCES `n_pays` (`pays_id`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table password_reset_tokens
DROP TABLE IF EXISTS `password_reset_tokens`;
CREATE TABLE `password_reset_tokens` (
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`email`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table personal_access_tokens
DROP TABLE IF EXISTS `personal_access_tokens`;
CREATE TABLE `personal_access_tokens` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tokenable_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tokenable_id` bigint unsigned NOT NULL,
  `name` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `abilities` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `last_used_at` timestamp NULL DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `personal_access_tokens_token_unique` (`token`),
  KEY `personal_access_tokens_tokenable_type_tokenable_id_index` (`tokenable_type`,`tokenable_id`),
  KEY `personal_access_tokens_expires_at_index` (`expires_at`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table sessions
DROP TABLE IF EXISTS `sessions`;
CREATE TABLE `sessions` (
  `id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `ip_address` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `last_activity` int NOT NULL,
  PRIMARY KEY (`id`),
  KEY `sessions_user_id_index` (`user_id`),
  KEY `sessions_last_activity_index` (`last_activity`)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


SET FOREIGN_KEY_CHECKS=1;
SET UNIQUE_CHECKS=1;
