-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- مضيف: localhost:3306
-- وقت الجيل: 29 أبريل 2026 الساعة 22:03
-- إصدار الخادم: 10.11.16-MariaDB
-- نسخة PHP: 8.4.20

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- قاعدة بيانات: `schoolstudents_test`
--

-- --------------------------------------------------------

--
-- بنية الجدول `academic_terms`
--

CREATE TABLE `academic_terms` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `activity_logs`
--

CREATE TABLE `activity_logs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `event_type` varchar(50) NOT NULL,
  `page_name` varchar(100) DEFAULT NULL,
  `edu_key` varchar(30) DEFAULT NULL,
  `school_wiz_code` varchar(50) DEFAULT NULL,
  `reference_id` bigint(20) UNSIGNED DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`payload_json`)),
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `ahsa`
--

CREATE TABLE `ahsa` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `app_admins`
--

CREATE TABLE `app_admins` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `username` varchar(100) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `display_name` varchar(150) DEFAULT NULL,
  `role` enum('print_rep','super_admin') NOT NULL DEFAULT 'print_rep',
  `region_key` varchar(50) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `last_login_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `aseer`
--

CREATE TABLE `aseer` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `baha`
--

CREATE TABLE `baha` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `carton_capacity_settings`
--

CREATE TABLE `carton_capacity_settings` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `education_type_name` varchar(100) NOT NULL,
  `grade_name` varchar(100) NOT NULL,
  `carton_capacity` int(11) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `notes` varchar(255) DEFAULT NULL,
  `created_by` varchar(100) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `delivery_note_email_logs`
--

CREATE TABLE `delivery_note_email_logs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `principal_email` varchar(190) NOT NULL,
  `principal_name` varchar(255) DEFAULT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `schools_count` int(11) NOT NULL DEFAULT 0,
  `status` enum('pending','sent','failed') NOT NULL DEFAULT 'pending',
  `error_message` text DEFAULT NULL,
  `sent_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `delivery_note_email_log_schools`
--

CREATE TABLE `delivery_note_email_log_schools` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `email_log_id` bigint(20) UNSIGNED NOT NULL,
  `school_id` bigint(20) UNSIGNED NOT NULL,
  `ministry_code` varchar(50) NOT NULL,
  `short_code` varchar(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `delivery_note_links`
--

CREATE TABLE `delivery_note_links` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `school_id` bigint(20) UNSIGNED NOT NULL,
  `ministry_code` varchar(50) NOT NULL,
  `short_code` varchar(20) NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `last_access_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `eastern`
--

CREATE TABLE `eastern` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `education_admins`
--

CREATE TABLE `education_admins` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `admin_name` varchar(255) NOT NULL,
  `admin_code` varchar(100) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `education_types_ref`
--

CREATE TABLE `education_types_ref` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `type_name` varchar(100) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `grades_ref`
--

CREATE TABLE `grades_ref` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `grade_key` varchar(20) NOT NULL,
  `grade_name` varchar(100) NOT NULL,
  `stage_name` varchar(100) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `hail`
--

CREATE TABLE `hail` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `import_batches`
--

CREATE TABLE `import_batches` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `table_name` varchar(50) NOT NULL,
  `source_file` varchar(255) NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `uploaded_by_admin_id` bigint(20) UNSIGNED DEFAULT NULL,
  `uploaded_by_username` varchar(100) DEFAULT NULL,
  `total_inserted` int(11) NOT NULL DEFAULT 0,
  `total_flagged` int(11) NOT NULL DEFAULT 0,
  `total_skipped` int(11) NOT NULL DEFAULT 0,
  `started_at` datetime NOT NULL DEFAULT current_timestamp(),
  `finished_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `import_review_queue`
--

CREATE TABLE `import_review_queue` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `batch_id` bigint(20) UNSIGNED NOT NULL,
  `table_name` varchar(50) NOT NULL,
  `line_no` int(11) NOT NULL,
  `issue_code` varchar(50) NOT NULL,
  `issue_label` varchar(255) NOT NULL,
  `raw_national_id` varchar(255) DEFAULT NULL,
  `suggested_national_id` varchar(50) DEFAULT NULL,
  `student_name` varchar(255) DEFAULT NULL,
  `school_name` varchar(255) DEFAULT NULL,
  `ministry_code` varchar(50) DEFAULT NULL,
  `row_json` longtext DEFAULT NULL,
  `status` enum('new','reviewed','fixed','ignored') NOT NULL DEFAULT 'new',
  `review_notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `jazan`
--

CREATE TABLE `jazan` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `jeddah`
--

CREATE TABLE `jeddah` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `jouf`
--

CREATE TABLE `jouf` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `madinah`
--

CREATE TABLE `madinah` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `makkah`
--

CREATE TABLE `makkah` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `najran`
--

CREATE TABLE `najran` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `northern`
--

CREATE TABLE `northern` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `portal_settings`
--

CREATE TABLE `portal_settings` (
  `setting_key` varchar(120) NOT NULL,
  `setting_value` text DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `printers`
--

CREATE TABLE `printers` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `printer_name` varchar(255) NOT NULL,
  `contact_name` varchar(255) DEFAULT NULL,
  `contact_mobile` varchar(30) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `printer_users`
--

CREATE TABLE `printer_users` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `printer_id` bigint(20) UNSIGNED NOT NULL,
  `username` varchar(100) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `display_name` varchar(150) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `last_login_at` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `print_error_reports`
--

CREATE TABLE `print_error_reports` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `report_no` varchar(30) DEFAULT NULL,
  `edu_key` varchar(30) NOT NULL,
  `school_wiz_code` varchar(50) NOT NULL,
  `school_name` varchar(300) NOT NULL,
  `school_gender` varchar(50) DEFAULT NULL,
  `principal_name` varchar(200) NOT NULL,
  `principal_mobile` varchar(30) NOT NULL,
  `receiver_name` varchar(200) DEFAULT NULL,
  `receiver_mobile` varchar(30) DEFAULT NULL,
  `receiver_role` varchar(100) DEFAULT NULL,
  `academic_year` varchar(20) DEFAULT NULL,
  `term_name` varchar(50) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `status` enum('new','reviewed','sent_to_printer','completed','cancelled') NOT NULL DEFAULT 'new',
  `region_review_status` varchar(30) NOT NULL DEFAULT 'pending',
  `region_reviewed_by` bigint(20) UNSIGNED DEFAULT NULL,
  `region_reviewed_at` datetime DEFAULT NULL,
  `region_review_notes` text DEFAULT NULL,
  `sent_to_printer_at` datetime DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `print_error_report_attachments`
--

CREATE TABLE `print_error_report_attachments` (
  `id` int(10) UNSIGNED NOT NULL,
  `report_id` int(11) NOT NULL,
  `original_filename` varchar(255) NOT NULL,
  `stored_filename` varchar(255) NOT NULL,
  `file_path` varchar(500) NOT NULL,
  `mime_type` varchar(120) DEFAULT NULL,
  `file_size` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `uploaded_by_type` varchar(30) DEFAULT NULL,
  `uploaded_by_id` varchar(80) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `print_error_report_items`
--

CREATE TABLE `print_error_report_items` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `report_id` bigint(20) UNSIGNED NOT NULL,
  `subject_catalog_id` bigint(20) UNSIGNED DEFAULT NULL,
  `subject_name` varchar(255) NOT NULL,
  `period_type` enum('term','part','year') DEFAULT NULL,
  `period_value` varchar(30) DEFAULT NULL,
  `coverage_type` enum('single','extended') DEFAULT NULL,
  `track_name` varchar(150) DEFAULT NULL,
  `grade_name` varchar(120) NOT NULL,
  `quantity` int(10) UNSIGNED NOT NULL,
  `error_description` varchar(500) DEFAULT NULL,
  `printer_id` bigint(20) UNSIGNED DEFAULT NULL,
  `sort_order` int(10) UNSIGNED NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `qassim`
--

CREATE TABLE `qassim` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `region_support_contacts`
--

CREATE TABLE `region_support_contacts` (
  `region_key` varchar(80) NOT NULL,
  `contact_name` varchar(190) DEFAULT NULL,
  `contact_mobile` varchar(30) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `riyadh_1`
--

CREATE TABLE `riyadh_1` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `riyadh_2`
--

CREATE TABLE `riyadh_2` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `schools_master`
--

CREATE TABLE `schools_master` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ministry_code` varchar(50) NOT NULL,
  `school_name` varchar(255) NOT NULL,
  `education_admin_id` bigint(20) UNSIGNED NOT NULL,
  `governorate_name` varchar(100) DEFAULT NULL,
  `stage_id` bigint(20) UNSIGNED NOT NULL,
  `authority_id` bigint(20) UNSIGNED NOT NULL,
  `gender_id` bigint(20) UNSIGNED NOT NULL,
  `education_type_id` bigint(20) UNSIGNED NOT NULL,
  `shift_id` bigint(20) UNSIGNED NOT NULL,
  `principal_name` varchar(255) DEFAULT NULL,
  `principal_national_id` varchar(20) DEFAULT NULL,
  `principal_mobile` varchar(30) DEFAULT NULL,
  `principal_email` varchar(190) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_authorities_ref`
--

CREATE TABLE `school_authorities_ref` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `authority_name` varchar(100) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_delivery_receipts`
--

CREATE TABLE `school_delivery_receipts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `school_id` bigint(20) UNSIGNED NOT NULL,
  `ministry_code` varchar(50) NOT NULL,
  `source_type` varchar(30) NOT NULL,
  `receipt_status` varchar(30) NOT NULL DEFAULT 'complete',
  `notes` text DEFAULT NULL,
  `batch_id` bigint(20) UNSIGNED DEFAULT NULL,
  `actor_type` varchar(30) NOT NULL DEFAULT 'system',
  `actor_id` varchar(80) DEFAULT NULL,
  `actor_name` varchar(190) DEFAULT NULL,
  `is_current` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_genders_ref`
--

CREATE TABLE `school_genders_ref` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `gender_name` varchar(50) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_grade_enrollments`
--

CREATE TABLE `school_grade_enrollments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `school_id` bigint(20) UNSIGNED NOT NULL,
  `grade_id` bigint(20) UNSIGNED NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `student_count` int(11) NOT NULL DEFAULT 0,
  `import_batch_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_import_batches`
--

CREATE TABLE `school_import_batches` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `source_file` varchar(255) NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `total_rows` int(11) NOT NULL DEFAULT 0,
  `processed_rows` int(11) NOT NULL DEFAULT 0,
  `inserted_schools` int(11) NOT NULL DEFAULT 0,
  `updated_schools` int(11) NOT NULL DEFAULT 0,
  `inserted_enrollments` int(11) NOT NULL DEFAULT 0,
  `skipped_rows` int(11) NOT NULL DEFAULT 0,
  `notes` text DEFAULT NULL,
  `created_by` varchar(100) DEFAULT NULL,
  `started_at` datetime NOT NULL DEFAULT current_timestamp(),
  `finished_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_shifts_ref`
--

CREATE TABLE `school_shifts_ref` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `shift_name` varchar(50) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `school_stages`
--

CREATE TABLE `school_stages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `stage_name` varchar(100) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `student_material_delivery`
--

CREATE TABLE `student_material_delivery` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `school_id` bigint(20) UNSIGNED NOT NULL,
  `student_table_name` varchar(50) NOT NULL,
  `student_row_id` int(10) UNSIGNED NOT NULL,
  `student_national_id` varchar(100) DEFAULT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `delivered` tinyint(1) NOT NULL DEFAULT 0,
  `delivered_at` datetime DEFAULT NULL,
  `delivered_by` varchar(100) DEFAULT NULL,
  `notes` varchar(255) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `student_transfer_actions`
--

CREATE TABLE `student_transfer_actions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `transfer_record_id` bigint(20) UNSIGNED NOT NULL,
  `action_type` varchar(60) NOT NULL,
  `notes` text DEFAULT NULL,
  `actor_type` varchar(30) NOT NULL DEFAULT 'system',
  `actor_id` varchar(80) DEFAULT NULL,
  `actor_name` varchar(190) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `student_transfer_import_batches`
--

CREATE TABLE `student_transfer_import_batches` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `original_filename` varchar(255) DEFAULT NULL,
  `source_type` varchar(30) NOT NULL DEFAULT 'upload',
  `file_hash` char(64) DEFAULT NULL,
  `imported_by_admin_id` bigint(20) UNSIGNED DEFAULT NULL,
  `imported_by_name` varchar(190) DEFAULT NULL,
  `import_mode` varchar(30) NOT NULL DEFAULT 'replace_current',
  `rows_total` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_valid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_invalid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_inserted` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_unmatched_students` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_unmatched_new_schools` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_cross_region` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_internal_region` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_same_school` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `student_transfer_records`
--

CREATE TABLE `student_transfer_records` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `batch_id` bigint(20) UNSIGNED NOT NULL,
  `national_id` varchar(20) NOT NULL,
  `student_name` varchar(255) DEFAULT NULL,
  `movement_status` varchar(120) DEFAULT NULL,
  `old_school_code` varchar(50) DEFAULT NULL,
  `old_school_name` varchar(255) DEFAULT NULL,
  `old_education_admin_name` varchar(255) DEFAULT NULL,
  `new_school_code` varchar(50) NOT NULL,
  `new_school_name` varchar(255) DEFAULT NULL,
  `new_education_admin_name` varchar(255) DEFAULT NULL,
  `snapshot_school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `snapshot_school_code` varchar(50) DEFAULT NULL,
  `snapshot_school_name` varchar(255) DEFAULT NULL,
  `snapshot_education_admin_name` varchar(255) DEFAULT NULL,
  `snapshot_student_table` varchar(80) DEFAULT NULL,
  `snapshot_student_row_id` bigint(20) UNSIGNED DEFAULT NULL,
  `academic_year` varchar(20) DEFAULT NULL,
  `term_name` varchar(50) DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_name` varchar(120) DEFAULT NULL,
  `new_school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `new_school_resolved_name` varchar(255) DEFAULT NULL,
  `new_education_admin_resolved_name` varchar(255) DEFAULT NULL,
  `snapshot_region_key` varchar(80) DEFAULT NULL,
  `new_region_key` varchar(80) DEFAULT NULL,
  `transfer_type` varchar(40) NOT NULL DEFAULT 'unknown',
  `is_current` tinyint(1) NOT NULL DEFAULT 1,
  `row_hash` char(64) DEFAULT NULL,
  `source_row_number` int(10) UNSIGNED DEFAULT NULL,
  `raw_json` longtext DEFAULT NULL,
  `first_seen_at` datetime NOT NULL DEFAULT current_timestamp(),
  `last_seen_at` datetime NOT NULL DEFAULT current_timestamp(),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `subjects_catalog`
--

CREATE TABLE `subjects_catalog` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `grade_name` varchar(100) NOT NULL,
  `education_type_name` varchar(100) NOT NULL DEFAULT 'تعليم عام',
  `stage_name` varchar(100) NOT NULL DEFAULT '',
  `period_type` enum('term','part','year') NOT NULL DEFAULT 'term',
  `period_value` varchar(30) NOT NULL DEFAULT '',
  `coverage_type` enum('single','extended') NOT NULL DEFAULT 'single',
  `track_name` varchar(150) DEFAULT NULL,
  `edition_label` varchar(150) DEFAULT NULL,
  `subject_name` varchar(255) NOT NULL,
  `subject_code` varchar(100) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `subject_printer_assignments`
--

CREATE TABLE `subject_printer_assignments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `academic_year` varchar(20) NOT NULL,
  `term_name` varchar(50) NOT NULL,
  `subject_catalog_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_name` varchar(100) NOT NULL,
  `subject_name` varchar(255) NOT NULL,
  `printer_id` bigint(20) UNSIGNED NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `system_audit_logs`
--

CREATE TABLE `system_audit_logs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `actor_type` varchar(30) NOT NULL DEFAULT 'system',
  `actor_id` varchar(80) DEFAULT NULL,
  `actor_name` varchar(190) DEFAULT NULL,
  `action` varchar(80) NOT NULL,
  `entity_type` varchar(80) DEFAULT NULL,
  `entity_id` varchar(80) DEFAULT NULL,
  `school_id` int(11) DEFAULT NULL,
  `ministry_code` varchar(50) DEFAULT NULL,
  `ip_address` varchar(64) DEFAULT NULL,
  `user_agent` varchar(255) DEFAULT NULL,
  `details_json` longtext DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `tabuk`
--

CREATE TABLE `tabuk` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `taif`
--

CREATE TABLE `taif` (
  `id` int(10) UNSIGNED NOT NULL,
  `السجل المدني` varchar(100) DEFAULT NULL,
  `اسم الطالب` varchar(200) DEFAULT NULL,
  `school_id` bigint(20) UNSIGNED DEFAULT NULL,
  `grade_id` bigint(20) UNSIGNED DEFAULT NULL,
  `العام الدراسي` varchar(20) DEFAULT NULL,
  `الفصل الدراسي` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- بنية الجدول `transport_delivery_import_batches`
--

CREATE TABLE `transport_delivery_import_batches` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `original_filename` varchar(255) DEFAULT NULL,
  `source_type` varchar(30) NOT NULL DEFAULT 'upload',
  `file_hash` char(64) DEFAULT NULL,
  `imported_by_admin_id` bigint(20) UNSIGNED DEFAULT NULL,
  `imported_by_name` varchar(190) DEFAULT NULL,
  `import_mode` varchar(30) NOT NULL DEFAULT 'append_update',
  `rows_total` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_valid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_invalid` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_matched` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_unmatched` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_complete` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `rows_partial` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `notes` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- فهارس للجدول `academic_terms`
--
ALTER TABLE `academic_terms`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_academic_terms` (`academic_year`,`term_name`),
  ADD KEY `idx_active_term` (`is_active`);

--
-- فهارس للجدول `activity_logs`
--
ALTER TABLE `activity_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_event_type` (`event_type`),
  ADD KEY `idx_page_name` (`page_name`),
  ADD KEY `idx_school_wiz_code` (`school_wiz_code`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_ref` (`reference_id`);

--
-- فهارس للجدول `ahsa`
--
ALTER TABLE `ahsa`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `app_admins`
--
ALTER TABLE `app_admins`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_app_admins_username` (`username`),
  ADD KEY `idx_app_admins_region_key` (`region_key`);

--
-- فهارس للجدول `aseer`
--
ALTER TABLE `aseer`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `baha`
--
ALTER TABLE `baha`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `carton_capacity_settings`
--
ALTER TABLE `carton_capacity_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_carton_capacity_term_type_grade` (`academic_year`,`term_name`,`education_type_name`,`grade_name`),
  ADD KEY `idx_carton_capacity_lookup` (`academic_year`,`term_name`,`is_active`);

--
-- فهارس للجدول `delivery_note_email_logs`
--
ALTER TABLE `delivery_note_email_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_email_term` (`principal_email`,`academic_year`,`term_name`),
  ADD KEY `idx_status` (`status`);

--
-- فهارس للجدول `delivery_note_email_log_schools`
--
ALTER TABLE `delivery_note_email_log_schools`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_email_log_id` (`email_log_id`),
  ADD KEY `idx_school_id` (`school_id`);

--
-- فهارس للجدول `delivery_note_links`
--
ALTER TABLE `delivery_note_links`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_delivery_note_short_code` (`short_code`),
  ADD UNIQUE KEY `uq_delivery_note_school_term` (`school_id`,`academic_year`,`term_name`),
  ADD KEY `idx_delivery_note_ministry` (`ministry_code`);

--
-- فهارس للجدول `eastern`
--
ALTER TABLE `eastern`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `education_admins`
--
ALTER TABLE `education_admins`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_education_admins_name` (`admin_name`);

--
-- فهارس للجدول `education_types_ref`
--
ALTER TABLE `education_types_ref`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_education_types_ref_name` (`type_name`);

--
-- فهارس للجدول `grades_ref`
--
ALTER TABLE `grades_ref`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_grades_ref_key` (`grade_key`),
  ADD UNIQUE KEY `uq_grades_ref_name` (`grade_name`);

--
-- فهارس للجدول `hail`
--
ALTER TABLE `hail`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `import_batches`
--
ALTER TABLE `import_batches`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_import_batches_table` (`table_name`),
  ADD KEY `idx_import_batches_started` (`started_at`);

--
-- فهارس للجدول `import_review_queue`
--
ALTER TABLE `import_review_queue`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_review_batch` (`batch_id`),
  ADD KEY `idx_review_table_status` (`table_name`,`status`),
  ADD KEY `idx_review_issue_code` (`issue_code`);

--
-- فهارس للجدول `jazan`
--
ALTER TABLE `jazan`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `jeddah`
--
ALTER TABLE `jeddah`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `jouf`
--
ALTER TABLE `jouf`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `madinah`
--
ALTER TABLE `madinah`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `makkah`
--
ALTER TABLE `makkah`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `najran`
--
ALTER TABLE `najran`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `northern`
--
ALTER TABLE `northern`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `portal_settings`
--
ALTER TABLE `portal_settings`
  ADD PRIMARY KEY (`setting_key`);

--
-- فهارس للجدول `printers`
--
ALTER TABLE `printers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_printers_name` (`printer_name`);

--
-- فهارس للجدول `printer_users`
--
ALTER TABLE `printer_users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_printer_users_username` (`username`),
  ADD KEY `idx_printer_users_printer` (`printer_id`);

--
-- فهارس للجدول `print_error_reports`
--
ALTER TABLE `print_error_reports`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_report_no` (`report_no`),
  ADD KEY `idx_edu_key` (`edu_key`),
  ADD KEY `idx_school_wiz_code` (`school_wiz_code`),
  ADD KEY `idx_status` (`status`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_school_status_date` (`school_wiz_code`,`status`,`created_at`),
  ADD KEY `idx_term` (`academic_year`,`term_name`),
  ADD KEY `idx_region_review_status` (`region_review_status`),
  ADD KEY `idx_edu_region_review_status` (`edu_key`,`region_review_status`),
  ADD KEY `idx_sent_to_printer_at` (`sent_to_printer_at`);

--
-- فهارس للجدول `print_error_report_attachments`
--
ALTER TABLE `print_error_report_attachments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_report_attachments_report` (`report_id`),
  ADD KEY `idx_report_attachments_created` (`created_at`);

--
-- فهارس للجدول `print_error_report_items`
--
ALTER TABLE `print_error_report_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_report_id` (`report_id`),
  ADD KEY `idx_grade_name` (`grade_name`),
  ADD KEY `idx_print_error_items_printer` (`printer_id`),
  ADD KEY `idx_peri_subject_catalog_id` (`subject_catalog_id`);

--
-- فهارس للجدول `qassim`
--
ALTER TABLE `qassim`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `region_support_contacts`
--
ALTER TABLE `region_support_contacts`
  ADD PRIMARY KEY (`region_key`);

--
-- فهارس للجدول `riyadh_1`
--
ALTER TABLE `riyadh_1`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `riyadh_2`
--
ALTER TABLE `riyadh_2`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `schools_master`
--
ALTER TABLE `schools_master`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_schools_master_ministry_code` (`ministry_code`),
  ADD KEY `idx_schools_master_admin` (`education_admin_id`),
  ADD KEY `idx_schools_master_stage` (`stage_id`),
  ADD KEY `idx_schools_master_type` (`education_type_id`),
  ADD KEY `fk_schools_master_authority` (`authority_id`),
  ADD KEY `fk_schools_master_gender` (`gender_id`),
  ADD KEY `fk_schools_master_shift` (`shift_id`),
  ADD KEY `idx_principal_email` (`principal_email`),
  ADD KEY `idx_principal_national_id` (`principal_national_id`);

--
-- فهارس للجدول `school_authorities_ref`
--
ALTER TABLE `school_authorities_ref`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_school_authorities_ref_name` (`authority_name`);

--
-- فهارس للجدول `school_delivery_receipts`
--
ALTER TABLE `school_delivery_receipts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_sdr_school_source` (`school_id`,`source_type`,`is_current`),
  ADD KEY `idx_sdr_ministry_source` (`ministry_code`,`source_type`,`is_current`),
  ADD KEY `idx_sdr_status` (`source_type`,`receipt_status`,`is_current`),
  ADD KEY `idx_sdr_batch` (`batch_id`);

--
-- فهارس للجدول `school_genders_ref`
--
ALTER TABLE `school_genders_ref`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_school_genders_ref_name` (`gender_name`);

--
-- فهارس للجدول `school_grade_enrollments`
--
ALTER TABLE `school_grade_enrollments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_school_grade_term` (`school_id`,`grade_id`,`academic_year`,`term_name`),
  ADD KEY `idx_school_grade_enrollments_school_term` (`school_id`,`academic_year`,`term_name`),
  ADD KEY `idx_school_grade_enrollments_grade` (`grade_id`),
  ADD KEY `fk_school_grade_enrollments_batch` (`import_batch_id`);

--
-- فهارس للجدول `school_import_batches`
--
ALTER TABLE `school_import_batches`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_school_import_batches_term` (`academic_year`,`term_name`);

--
-- فهارس للجدول `school_shifts_ref`
--
ALTER TABLE `school_shifts_ref`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_school_shifts_ref_name` (`shift_name`);

--
-- فهارس للجدول `school_stages`
--
ALTER TABLE `school_stages`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_school_stages_name` (`stage_name`);

--
-- فهارس للجدول `student_material_delivery`
--
ALTER TABLE `student_material_delivery`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_delivery_student_term` (`student_table_name`,`student_row_id`,`academic_year`,`term_name`),
  ADD KEY `idx_delivery_school_term` (`school_id`,`academic_year`,`term_name`),
  ADD KEY `idx_delivery_status` (`delivered`),
  ADD KEY `idx_delivery_national_id` (`student_national_id`);

--
-- فهارس للجدول `student_transfer_actions`
--
ALTER TABLE `student_transfer_actions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_sta_transfer` (`transfer_record_id`),
  ADD KEY `idx_sta_action_type` (`action_type`),
  ADD KEY `idx_sta_created_at` (`created_at`),
  ADD KEY `idx_sta_school` (`school_id`);

--
-- فهارس للجدول `student_transfer_import_batches`
--
ALTER TABLE `student_transfer_import_batches`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_stib_created_at` (`created_at`),
  ADD KEY `idx_stib_file_hash` (`file_hash`);

--
-- فهارس للجدول `student_transfer_records`
--
ALTER TABLE `student_transfer_records`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_str_batch` (`batch_id`),
  ADD KEY `idx_str_current_nid` (`is_current`,`national_id`),
  ADD KEY `idx_str_snapshot_school` (`is_current`,`snapshot_school_id`),
  ADD KEY `idx_str_new_school` (`is_current`,`new_school_id`),
  ADD KEY `idx_str_snapshot_region` (`is_current`,`snapshot_region_key`),
  ADD KEY `idx_str_new_region` (`is_current`,`new_region_key`),
  ADD KEY `idx_str_type` (`is_current`,`transfer_type`),
  ADD KEY `idx_str_old_code` (`old_school_code`),
  ADD KEY `idx_str_new_code` (`new_school_code`),
  ADD KEY `idx_str_last_seen` (`last_seen_at`);

--
-- فهارس للجدول `subjects_catalog`
--
ALTER TABLE `subjects_catalog`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_subject_catalog_full` (`academic_year`,`grade_name`,`education_type_name`,`stage_name`,`subject_name`,`period_type`,`period_value`,`coverage_type`,`track_name`),
  ADD KEY `idx_subjects_catalog_grade` (`grade_name`),
  ADD KEY `idx_subjects_catalog_lookup` (`academic_year`,`education_type_name`,`stage_name`,`grade_name`,`period_type`,`period_value`,`coverage_type`);

--
-- فهارس للجدول `subject_printer_assignments`
--
ALTER TABLE `subject_printer_assignments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_spa_subject` (`academic_year`,`subject_catalog_id`),
  ADD KEY `idx_subject_printer_printer` (`printer_id`),
  ADD KEY `idx_subject_printer_lookup` (`academic_year`,`term_name`,`printer_id`),
  ADD KEY `idx_spa_subject_catalog_id` (`subject_catalog_id`);

--
-- فهارس للجدول `system_audit_logs`
--
ALTER TABLE `system_audit_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_audit_created_at` (`created_at`),
  ADD KEY `idx_audit_actor` (`actor_type`,`actor_id`),
  ADD KEY `idx_audit_action` (`action`),
  ADD KEY `idx_audit_school` (`school_id`),
  ADD KEY `idx_audit_ministry_code` (`ministry_code`);

--
-- فهارس للجدول `tabuk`
--
ALTER TABLE `tabuk`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `taif`
--
ALTER TABLE `taif`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_civil` (`السجل المدني`),
  ADD KEY `idx_term` (`العام الدراسي`,`الفصل الدراسي`),
  ADD KEY `idx_grade_id` (`grade_id`),
  ADD KEY `idx_civil_school` (`السجل المدني`,`school_id`),
  ADD KEY `idx_school_id` (`school_id`),
  ADD KEY `idx_school_grade` (`school_id`,`grade_id`);

--
-- فهارس للجدول `transport_delivery_import_batches`
--
ALTER TABLE `transport_delivery_import_batches`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tdib_created_at` (`created_at`),
  ADD KEY `idx_tdib_file_hash` (`file_hash`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `academic_terms`
--
ALTER TABLE `academic_terms`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `activity_logs`
--
ALTER TABLE `activity_logs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `ahsa`
--
ALTER TABLE `ahsa`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `app_admins`
--
ALTER TABLE `app_admins`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `aseer`
--
ALTER TABLE `aseer`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `baha`
--
ALTER TABLE `baha`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `carton_capacity_settings`
--
ALTER TABLE `carton_capacity_settings`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `delivery_note_email_logs`
--
ALTER TABLE `delivery_note_email_logs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `delivery_note_email_log_schools`
--
ALTER TABLE `delivery_note_email_log_schools`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `delivery_note_links`
--
ALTER TABLE `delivery_note_links`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `eastern`
--
ALTER TABLE `eastern`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `education_admins`
--
ALTER TABLE `education_admins`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `education_types_ref`
--
ALTER TABLE `education_types_ref`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `grades_ref`
--
ALTER TABLE `grades_ref`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `hail`
--
ALTER TABLE `hail`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `import_batches`
--
ALTER TABLE `import_batches`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `import_review_queue`
--
ALTER TABLE `import_review_queue`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `jazan`
--
ALTER TABLE `jazan`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `jeddah`
--
ALTER TABLE `jeddah`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `jouf`
--
ALTER TABLE `jouf`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `madinah`
--
ALTER TABLE `madinah`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `makkah`
--
ALTER TABLE `makkah`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `najran`
--
ALTER TABLE `najran`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `northern`
--
ALTER TABLE `northern`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `printers`
--
ALTER TABLE `printers`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `printer_users`
--
ALTER TABLE `printer_users`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `print_error_reports`
--
ALTER TABLE `print_error_reports`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `print_error_report_attachments`
--
ALTER TABLE `print_error_report_attachments`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `print_error_report_items`
--
ALTER TABLE `print_error_report_items`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `qassim`
--
ALTER TABLE `qassim`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `riyadh_1`
--
ALTER TABLE `riyadh_1`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `riyadh_2`
--
ALTER TABLE `riyadh_2`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `schools_master`
--
ALTER TABLE `schools_master`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_authorities_ref`
--
ALTER TABLE `school_authorities_ref`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_delivery_receipts`
--
ALTER TABLE `school_delivery_receipts`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_genders_ref`
--
ALTER TABLE `school_genders_ref`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_grade_enrollments`
--
ALTER TABLE `school_grade_enrollments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_import_batches`
--
ALTER TABLE `school_import_batches`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_shifts_ref`
--
ALTER TABLE `school_shifts_ref`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `school_stages`
--
ALTER TABLE `school_stages`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `student_material_delivery`
--
ALTER TABLE `student_material_delivery`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `student_transfer_actions`
--
ALTER TABLE `student_transfer_actions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `student_transfer_import_batches`
--
ALTER TABLE `student_transfer_import_batches`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `student_transfer_records`
--
ALTER TABLE `student_transfer_records`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `subjects_catalog`
--
ALTER TABLE `subjects_catalog`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `subject_printer_assignments`
--
ALTER TABLE `subject_printer_assignments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `system_audit_logs`
--
ALTER TABLE `system_audit_logs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `tabuk`
--
ALTER TABLE `tabuk`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `taif`
--
ALTER TABLE `taif`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `transport_delivery_import_batches`
--
ALTER TABLE `transport_delivery_import_batches`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- القيود المفروضة على الجداول الملقاة
--

--
-- قيود الجداول `printer_users`
--
ALTER TABLE `printer_users`
  ADD CONSTRAINT `fk_printer_users_printer` FOREIGN KEY (`printer_id`) REFERENCES `printers` (`id`) ON DELETE CASCADE;

--
-- قيود الجداول `print_error_report_items`
--
ALTER TABLE `print_error_report_items`
  ADD CONSTRAINT `fk_peri_subject_catalog` FOREIGN KEY (`subject_catalog_id`) REFERENCES `subjects_catalog` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_print_error_report_items_printer` FOREIGN KEY (`printer_id`) REFERENCES `printers` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_print_error_report_items_report` FOREIGN KEY (`report_id`) REFERENCES `print_error_reports` (`id`) ON DELETE CASCADE;

--
-- قيود الجداول `schools_master`
--
ALTER TABLE `schools_master`
  ADD CONSTRAINT `fk_schools_master_admin` FOREIGN KEY (`education_admin_id`) REFERENCES `education_admins` (`id`),
  ADD CONSTRAINT `fk_schools_master_authority` FOREIGN KEY (`authority_id`) REFERENCES `school_authorities_ref` (`id`),
  ADD CONSTRAINT `fk_schools_master_gender` FOREIGN KEY (`gender_id`) REFERENCES `school_genders_ref` (`id`),
  ADD CONSTRAINT `fk_schools_master_shift` FOREIGN KEY (`shift_id`) REFERENCES `school_shifts_ref` (`id`),
  ADD CONSTRAINT `fk_schools_master_stage` FOREIGN KEY (`stage_id`) REFERENCES `school_stages` (`id`),
  ADD CONSTRAINT `fk_schools_master_type` FOREIGN KEY (`education_type_id`) REFERENCES `education_types_ref` (`id`);

--
-- قيود الجداول `school_grade_enrollments`
--
ALTER TABLE `school_grade_enrollments`
  ADD CONSTRAINT `fk_school_grade_enrollments_batch` FOREIGN KEY (`import_batch_id`) REFERENCES `school_import_batches` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_school_grade_enrollments_grade` FOREIGN KEY (`grade_id`) REFERENCES `grades_ref` (`id`),
  ADD CONSTRAINT `fk_school_grade_enrollments_school` FOREIGN KEY (`school_id`) REFERENCES `schools_master` (`id`) ON DELETE CASCADE;

--
-- قيود الجداول `subject_printer_assignments`
--
ALTER TABLE `subject_printer_assignments`
  ADD CONSTRAINT `fk_spa_subject_catalog` FOREIGN KEY (`subject_catalog_id`) REFERENCES `subjects_catalog` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_subject_printer_assignments_printer` FOREIGN KEY (`printer_id`) REFERENCES `printers` (`id`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
