-- phpMyAdmin SQL Dump
-- version 5.2.3
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Sep 30, 2026 at 01:17 PM
-- Server version: 11.4.13-MariaDB-cll-lve-log
-- PHP Version: 8.4.25

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 */;

--
-- Database: `easyyket_ceedeez`
--

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

--
-- Table structure for table `academic_sessions`
--

CREATE TABLE `academic_sessions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `session_year` varchar(20) NOT NULL COMMENT 'e.g. 2025/2026',
  `term` enum('1st','2nd','3rd') NOT NULL,
  `status` tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
  `app_view` int(11) DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `closing` varchar(150) DEFAULT NULL,
  `open` varchar(150) DEFAULT NULL,
  `no_open` int(11) NOT NULL DEFAULT 0,
  `no_opening` int(11) NOT NULL,
  `is_current` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1 = currently active session/term',
  `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;

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

--
-- Table structure for table `activity_participation`
--

CREATE TABLE `activity_participation` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `activity_id` bigint(20) UNSIGNED NOT NULL,
  `join_date` date NOT NULL,
  `status` varchar(50) DEFAULT 'active',
  `participation_level` varchar(100) DEFAULT NULL,
  `achievements` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `announcements`
--

CREATE TABLE `announcements` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(200) NOT NULL,
  `content` text NOT NULL,
  `type` enum('general','class','emergency','event') NOT NULL DEFAULT 'general',
  `target_class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `priority` enum('low','medium','high') DEFAULT 'medium',
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `expires_at` datetime DEFAULT NULL,
  `status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `app_settings`
--

CREATE TABLE `app_settings` (
  `id` int(11) NOT NULL,
  `setting_key` varchar(255) DEFAULT NULL,
  `setting_value` decimal(10,2) DEFAULT NULL,
  `download_link` varchar(500) DEFAULT NULL,
  `update_text` text DEFAULT NULL,
  `description` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `asdd`
--

CREATE TABLE `asdd` (
  `id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `full_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `student_class_id` bigint(20) UNSIGNED NOT NULL,
  `result_class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `subject_id` bigint(20) UNSIGNED NOT NULL,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `assignments`
--

CREATE TABLE `assignments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `subject_id` bigint(20) UNSIGNED NOT NULL,
  `teacher_id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(200) NOT NULL,
  `description` text DEFAULT NULL,
  `body` text NOT NULL,
  `instructions` text DEFAULT NULL,
  `assigned_date` date NOT NULL,
  `due_date` date NOT NULL,
  `due_time` time DEFAULT NULL,
  `assignment_type` varchar(50) DEFAULT 'homework',
  `pdf` varchar(1200) NOT NULL,
  `word` varchar(1200) NOT NULL,
  `total_marks` decimal(5,2) DEFAULT 0.00,
  `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;

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

--
-- Table structure for table `assignment_submissions`
--

CREATE TABLE `assignment_submissions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `assignment_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `submission_date` date NOT NULL,
  `submission_time` time NOT NULL,
  `submission_content` text DEFAULT NULL,
  `submission_status` varchar(50) DEFAULT 'pending',
  `marks_obtained` decimal(5,2) DEFAULT NULL,
  `teacher_feedback` text DEFAULT NULL,
  `graded_at` datetime DEFAULT NULL,
  `graded_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `attendance`
--

CREATE TABLE `attendance` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `class_id` int(11) NOT NULL,
  `session_id` int(11) DEFAULT NULL,
  `session_year` varchar(20) NOT NULL DEFAULT '2025/2026',
  `term` varchar(10) NOT NULL DEFAULT '1st',
  `attendance_date` date NOT NULL,
  `status` enum('present','absent','late','excused') NOT NULL,
  `reason` text DEFAULT NULL,
  `marked_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `latitude` decimal(10,8) DEFAULT NULL COMMENT 'GPS latitude coordinate',
  `longitude` decimal(11,8) DEFAULT NULL COMMENT 'GPS longitude coordinate',
  `accuracy` decimal(8,2) DEFAULT NULL COMMENT 'GPS accuracy in meters',
  `location_type` enum('school','pickup','dropoff') DEFAULT NULL COMMENT 'Type of location: school, pickup, or dropoff',
  `distance_from_school` decimal(10,2) DEFAULT NULL COMMENT 'Distance from school geofence in meters'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `beva1`
--

CREATE TABLE `beva1` (
  `regno` int(7) NOT NULL,
  `name` varchar(50) NOT NULL,
  `sex` varchar(20) NOT NULL,
  `class` varchar(120) NOT NULL,
  `arm` varchar(234) NOT NULL,
  `password` varchar(234) NOT NULL,
  `status` varchar(120) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `bursary_activity`
--

CREATE TABLE `bursary_activity` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `action` varchar(40) NOT NULL,
  `record_id` bigint(20) NOT NULL,
  `performed_by_id` bigint(20) UNSIGNED NOT NULL,
  `performed_by` varchar(255) NOT NULL,
  `snapshot` longtext NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `bursary_discounts`
--

CREATE TABLE `bursary_discounts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `description` text NOT NULL,
  `kind` enum('predefined','custom') NOT NULL,
  `value_type` enum('percentage','fixed') NOT NULL,
  `value` decimal(12,2) NOT NULL,
  `student_id` bigint(20) UNSIGNED DEFAULT NULL,
  `applies_to` enum('normal','other') NOT NULL,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL,
  `class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `category` varchar(150) NOT NULL DEFAULT '',
  `other_payment_item_id` bigint(20) UNSIGNED DEFAULT NULL,
  `starts_at` datetime DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  `is_active` tinyint(4) NOT NULL DEFAULT 1,
  `version` int(11) NOT NULL DEFAULT 1,
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `bursary_family_discount_allocations`
--

CREATE TABLE `bursary_family_discount_allocations` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `usage_id` bigint(20) UNSIGNED NOT NULL,
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `bursary_family_discount_usage`
--

CREATE TABLE `bursary_family_discount_usage` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `family_id` bigint(20) UNSIGNED NOT NULL,
  `session_id` varchar(64) NOT NULL,
  `charge_kind` varchar(20) NOT NULL,
  `scope_item_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `discount_id` bigint(20) UNSIGNED NOT NULL,
  `family_size` int(10) UNSIGNED NOT NULL,
  `discount_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `family_payment_id` bigint(20) UNSIGNED DEFAULT NULL,
  `receipt_number` varchar(80) DEFAULT NULL,
  `applied_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `bursary_family_payments`
--

CREATE TABLE `bursary_family_payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `receipt_number` varchar(100) NOT NULL,
  `session_id` varchar(20) NOT NULL,
  `payment_date` date NOT NULL,
  `payment_method` varchar(40) NOT NULL,
  `amount_paid` decimal(14,2) NOT NULL,
  `received_by_id` bigint(20) UNSIGNED NOT NULL,
  `received_by` varchar(255) NOT NULL,
  `receipt_snapshot` longtext NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `bursary_family_payment_lines`
--

CREATE TABLE `bursary_family_payment_lines` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `family_payment_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `payment_id` bigint(20) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `bursary_requests`
--

CREATE TABLE `bursary_requests` (
  `actor_id` bigint(20) UNSIGNED NOT NULL,
  `request_id` varchar(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `request_hash` char(64) NOT NULL,
  `result` longtext DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `cbt_answers`
--

CREATE TABLE `cbt_answers` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `question_id` int(11) NOT NULL,
  `question_order` int(11) NOT NULL DEFAULT 0,
  `answer` text NOT NULL COMMENT 'Student answer - can be JSON for multiple selections',
  `is_correct` tinyint(1) DEFAULT NULL,
  `marks_obtained` decimal(5,2) DEFAULT 0.00,
  `submitted_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `cbt_contexts`
--

CREATE TABLE `cbt_contexts` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `client_id` varchar(100) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `passage_text` text DEFAULT NULL,
  `context_image` longtext DEFAULT NULL,
  `order_index` int(11) NOT NULL DEFAULT 0,
  `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;

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

--
-- Table structure for table `cbt_questions`
--

CREATE TABLE `cbt_questions` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `context_id` int(11) DEFAULT NULL,
  `question_text` text NOT NULL,
  `question_type` enum('multiple_choice','true_false','short_answer') NOT NULL DEFAULT 'multiple_choice',
  `question_image` longtext DEFAULT NULL,
  `option_a` text DEFAULT NULL,
  `option_b` text DEFAULT NULL,
  `option_c` text DEFAULT NULL,
  `option_d` text DEFAULT NULL,
  `correct_answer` varchar(10) NOT NULL COMMENT 'A, B, C, D for multiple choice, or actual answer text',
  `marks` decimal(5,2) NOT NULL DEFAULT 1.00,
  `order_index` int(11) NOT NULL DEFAULT 0,
  `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;

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

--
-- Table structure for table `cbt_results`
--

CREATE TABLE `cbt_results` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `total_questions` int(11) NOT NULL,
  `attempted_questions` int(11) NOT NULL DEFAULT 0,
  `correct_answers` int(11) NOT NULL DEFAULT 0,
  `total_marks` decimal(7,2) NOT NULL DEFAULT 0.00,
  `marks_obtained` decimal(7,2) NOT NULL DEFAULT 0.00,
  `percentage` decimal(5,2) NOT NULL DEFAULT 0.00,
  `grade` varchar(5) DEFAULT NULL,
  `status` enum('pending','completed','graded') NOT NULL DEFAULT 'pending',
  `submitted_at` timestamp NULL DEFAULT NULL,
  `graded_at` timestamp NULL DEFAULT NULL,
  `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;

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

--
-- Table structure for table `cbt_tests`
--

CREATE TABLE `cbt_tests` (
  `id` int(11) NOT NULL,
  `test_title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `teacher_id` int(11) NOT NULL,
  `subject_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `class_ids` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'JSON array of class IDs this test serves' CHECK (json_valid(`class_ids`)),
  `session_id` int(11) NOT NULL,
  `student_id` int(11) DEFAULT NULL COMMENT 'NULL for class-wide tests, specific student ID for individual tests',
  `duration_minutes` int(11) NOT NULL DEFAULT 60,
  `total_questions` int(11) NOT NULL DEFAULT 0,
  `display_questions` int(11) DEFAULT NULL,
  `passing_score` decimal(5,2) NOT NULL DEFAULT 50.00,
  `status` enum('draft','active','completed','archived') NOT NULL DEFAULT 'draft',
  `test_type` enum('class','subject') DEFAULT 'class' COMMENT 'class = single class, subject = multi-class',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `start_date` datetime DEFAULT NULL,
  `end_date` datetime DEFAULT NULL,
  `sync_status` varchar(50) DEFAULT 'synced' COMMENT 'Sync status: synced (default) | local (pending push) | conflict (resolved locally)',
  `local_modified_at` timestamp NULL DEFAULT NULL COMMENT 'Timestamp when test was last modified in offline mode. Used for conflict detection.',
  `sync_source` varchar(50) DEFAULT NULL COMMENT 'Indicates record origin during sync: local | online | null (both sources)'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `cbt_test_assignments`
--

CREATE TABLE `cbt_test_assignments` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `assigned_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `accessed_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `status` enum('assigned','accessed','completed') NOT NULL DEFAULT 'assigned',
  `sync_source` varchar(50) DEFAULT 'online' COMMENT 'Record origin: online (default) | local (created offline)',
  `created_offline_at` timestamp NULL DEFAULT NULL COMMENT 'Timestamp when assignment was created in offline mode'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `cbt_test_classes`
--

CREATE TABLE `cbt_test_classes` (
  `id` int(11) NOT NULL,
  `test_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `classes`
--

CREATE TABLE `classes` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `section_id` bigint(20) UNSIGNED DEFAULT NULL,
  `class_name` varchar(50) NOT NULL,
  `section` varchar(20) DEFAULT NULL,
  `class_teacher_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `discipline_records`
--

CREATE TABLE `discipline_records` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `incident_date` date NOT NULL,
  `incident_type` varchar(100) DEFAULT NULL,
  `severity` varchar(50) DEFAULT 'minor',
  `description` text DEFAULT NULL,
  `action_taken` text DEFAULT NULL,
  `reported_by` bigint(20) UNSIGNED NOT NULL,
  `parent_notified` tinyint(1) DEFAULT 0,
  `notification_date` date DEFAULT NULL,
  `status` varchar(50) DEFAULT 'pending_action',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `events`
--

CREATE TABLE `events` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `event_name` varchar(200) NOT NULL,
  `event_description` text DEFAULT NULL,
  `event_type` varchar(50) DEFAULT 'general',
  `session_year` varchar(20) NOT NULL DEFAULT '2025/2026',
  `term` varchar(10) DEFAULT NULL,
  `event_date` date NOT NULL,
  `start_time` time DEFAULT NULL,
  `end_time` time DEFAULT NULL,
  `location` varchar(255) DEFAULT NULL,
  `target_class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `is_public` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `extracurricular_activities`
--

CREATE TABLE `extracurricular_activities` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `activity_name` varchar(100) NOT NULL,
  `activity_type` varchar(50) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `end_date` date DEFAULT NULL,
  `meeting_day` varchar(20) DEFAULT NULL,
  `meeting_time` time DEFAULT NULL,
  `location` varchar(255) DEFAULT NULL,
  `coordinator_id` bigint(20) UNSIGNED NOT NULL,
  `session_year` varchar(20) DEFAULT '2025/2026',
  `is_active` tinyint(1) 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;

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

--
-- Table structure for table `families`
--

CREATE TABLE `families` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `family_code` varchar(30) NOT NULL,
  `family_name` varchar(150) NOT NULL,
  `guardian_name` varchar(150) DEFAULT NULL,
  `guardian_phone` varchar(30) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fees`
--

CREATE TABLE `fees` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `session_id` varchar(20) NOT NULL,
  `student_type` enum('0','1') NOT NULL,
  `amount_due` decimal(12,2) NOT NULL,
  `amount_paid` decimal(12,2) DEFAULT 0.00,
  `balance` decimal(12,2) GENERATED ALWAYS AS (`amount_due` - `amount_paid`) STORED,
  `due_date` date DEFAULT NULL,
  `fee_items` varchar(200) NOT NULL,
  `payment_date` date DEFAULT NULL,
  `payment_method` varchar(50) DEFAULT NULL,
  `receipt_number` varchar(50) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `original_amount` decimal(12,2) DEFAULT NULL,
  `discount_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `family_discount_amount` decimal(12,2) DEFAULT 0.00,
  `applied_discount` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `feess`
--

CREATE TABLE `feess` (
  `regno` int(11) NOT NULL,
  `name` varchar(900) NOT NULL,
  `grade` varchar(900) NOT NULL,
  `vocational` varchar(900) NOT NULL,
  `uniform` varchar(900) NOT NULL,
  `clubsport` varchar(900) NOT NULL,
  `practical` varchar(900) NOT NULL,
  `ictfee` varchar(900) NOT NULL,
  `xmas` varchar(900) NOT NULL,
  `caution` varchar(900) NOT NULL,
  `graduation` varchar(900) NOT NULL,
  `pastquestion` varchar(900) NOT NULL,
  `externalexam` varchar(900) NOT NULL,
  `igsce` varchar(900) NOT NULL,
  `1stterm` varchar(900) NOT NULL,
  `2ndterm` varchar(900) NOT NULL,
  `3rdterm` varchar(900) NOT NULL,
  `total` varchar(900) NOT NULL,
  `nbn` varchar(900) NOT NULL,
  `nbna` varchar(900) NOT NULL,
  `w2` varchar(900) NOT NULL,
  `w3` varchar(900) NOT NULL,
  `w4` varchar(900) NOT NULL,
  `w22` varchar(900) NOT NULL,
  `w33` varchar(900) NOT NULL,
  `w44` varchar(900) NOT NULL,
  `w222` varchar(900) NOT NULL,
  `w333` varchar(900) NOT NULL,
  `w444` varchar(900) NOT NULL,
  `w122` varchar(900) NOT NULL,
  `w212` varchar(900) NOT NULL,
  `w233` varchar(900) NOT NULL,
  `w244` varchar(900) NOT NULL,
  `w344` varchar(900) NOT NULL,
  `w3444` varchar(900) NOT NULL,
  `w544` varchar(900) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fee_charge_details`
--

CREATE TABLE `fee_charge_details` (
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `charge_kind` enum('normal','other') NOT NULL,
  `title` varchar(150) NOT NULL,
  `description` text NOT NULL,
  `category` varchar(150) NOT NULL DEFAULT '',
  `class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `student_name` varchar(255) NOT NULL,
  `items_snapshot` longtext NOT NULL,
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `created_by_name` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `fee_discounts`
--

CREATE TABLE `fee_discounts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `discount_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `kind` enum('predefined','custom') NOT NULL,
  `value_type` enum('percentage','fixed') NOT NULL,
  `value` decimal(12,2) NOT NULL,
  `original_amount` decimal(12,2) NOT NULL,
  `eligible_balance` decimal(12,2) NOT NULL,
  `discount_amount` decimal(12,2) NOT NULL,
  `payable_amount` decimal(12,2) NOT NULL,
  `definition_snapshot` longtext NOT NULL,
  `applied_by` bigint(20) UNSIGNED NOT NULL,
  `applied_by_name` varchar(255) NOT NULL,
  `applied_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fee_items`
--

CREATE TABLE `fee_items` (
  `id` int(11) NOT NULL,
  `fee_name` varchar(100) NOT NULL,
  `class_id` int(11) NOT NULL,
  `new_amount` int(11) NOT NULL,
  `old_amount` int(11) NOT NULL,
  `compulsory` tinyint(1) NOT NULL,
  `session_id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fee_payments`
--

CREATE TABLE `fee_payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `session_id` varchar(20) NOT NULL,
  `amount_paid` decimal(12,2) NOT NULL,
  `payment_date` date NOT NULL,
  `payment_method` varchar(40) DEFAULT NULL,
  `receipt_number` varchar(80) NOT NULL,
  `settlement_reference` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fee_payment_allocations`
--

CREATE TABLE `fee_payment_allocations` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `payment_id` bigint(20) UNSIGNED NOT NULL,
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `amount_applied` decimal(12,2) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `fee_payment_details`
--

CREATE TABLE `fee_payment_details` (
  `payment_id` bigint(20) UNSIGNED NOT NULL,
  `fee_id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(150) NOT NULL,
  `charge_kind` enum('normal','other') NOT NULL,
  `original_amount` decimal(12,2) NOT NULL,
  `discount_amount` decimal(12,2) NOT NULL,
  `family_discount_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `amount_due` decimal(12,2) NOT NULL,
  `balance` decimal(12,2) NOT NULL,
  `received_by_id` bigint(20) UNSIGNED NOT NULL,
  `received_by` varchar(255) NOT NULL,
  `student_name` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `grading_keys`
--

CREATE TABLE `grading_keys` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `min_score` int(11) DEFAULT NULL,
  `max_score` int(11) DEFAULT NULL,
  `grade` varchar(10) NOT NULL,
  `remark` varchar(50) NOT NULL,
  `color_hex` varchar(7) DEFAULT NULL,
  `sort_order` int(11) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `grading_playclass`
--

CREATE TABLE `grading_playclass` (
  `id` int(11) NOT NULL,
  `grade` varchar(5) NOT NULL,
  `remark` varchar(50) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `inventory_categories`
--

CREATE TABLE `inventory_categories` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `description` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `version` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `inventory_issuances`
--

CREATE TABLE `inventory_issuances` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED DEFAULT NULL,
  `recipient` varchar(255) NOT NULL,
  `department` varchar(150) NOT NULL DEFAULT '',
  `date` date NOT NULL,
  `reference` varchar(150) NOT NULL,
  `notes` text NOT NULL,
  `issued_by` bigint(20) UNSIGNED NOT NULL,
  `issued_by_name` varchar(255) NOT NULL,
  `request_id` varchar(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `request_hash` char(64) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `inventory_issuance_items`
--

CREATE TABLE `inventory_issuance_items` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `issuance_id` bigint(20) UNSIGNED NOT NULL,
  `inventory_item_id` bigint(20) UNSIGNED NOT NULL,
  `movement_id` bigint(20) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `inventory_items`
--

CREATE TABLE `inventory_items` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `sku` varchar(80) NOT NULL,
  `category_id` bigint(20) UNSIGNED DEFAULT NULL,
  `unit` varchar(40) NOT NULL,
  `reorder_level` decimal(12,2) NOT NULL DEFAULT 0.00,
  `current_quantity` decimal(12,2) NOT NULL DEFAULT 0.00,
  `unit_cost` decimal(18,4) NOT NULL DEFAULT 0.0000,
  `stock_value` decimal(24,4) NOT NULL DEFAULT 0.0000,
  `location` varchar(200) NOT NULL DEFAULT '',
  `description` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `version` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `inventory_movements`
--

CREATE TABLE `inventory_movements` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `item_id` bigint(20) UNSIGNED NOT NULL,
  `item_name` varchar(150) NOT NULL,
  `sku` varchar(80) NOT NULL,
  `unit` varchar(40) NOT NULL,
  `type` enum('in','out','adjustment') NOT NULL,
  `direction` enum('increase','decrease') NOT NULL,
  `quantity` decimal(12,2) NOT NULL,
  `previous_quantity` decimal(12,2) NOT NULL,
  `new_quantity` decimal(12,2) NOT NULL,
  `unit_cost` decimal(18,4) NOT NULL,
  `total_cost` decimal(24,4) NOT NULL,
  `previous_value` decimal(24,4) NOT NULL,
  `new_value` decimal(24,4) NOT NULL,
  `date` date NOT NULL,
  `reference` varchar(150) NOT NULL DEFAULT '',
  `supplier_id` bigint(20) UNSIGNED DEFAULT NULL,
  `supplier_name` varchar(150) NOT NULL DEFAULT '',
  `recipient` varchar(150) NOT NULL DEFAULT '',
  `department` varchar(150) NOT NULL DEFAULT '',
  `notes` text DEFAULT NULL,
  `performed_by_id` bigint(20) UNSIGNED NOT NULL,
  `performed_by` varchar(150) NOT NULL,
  `request_id` varchar(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `request_hash` char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `inventory_suppliers`
--

CREATE TABLE `inventory_suppliers` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `contact_person` varchar(150) NOT NULL DEFAULT '',
  `phone` varchar(40) NOT NULL DEFAULT '',
  `email` varchar(254) NOT NULL DEFAULT '',
  `address` text DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `supplied_items` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `version` int(10) UNSIGNED NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `library_books`
--

CREATE TABLE `library_books` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `book_title` varchar(255) NOT NULL,
  `author` varchar(255) DEFAULT NULL,
  `published_year` smallint(4) DEFAULT NULL,
  `book_author` varchar(150) DEFAULT NULL,
  `isbn` varchar(20) DEFAULT NULL,
  `book_code` varchar(50) NOT NULL,
  `category` varchar(100) DEFAULT NULL,
  `publication_year` int(11) DEFAULT NULL,
  `publisher` varchar(150) DEFAULT NULL,
  `total_copies` int(11) DEFAULT 1,
  `available_copies` int(11) DEFAULT 1,
  `book_description` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `library_borrowing`
--

CREATE TABLE `library_borrowing` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `book_id` bigint(20) UNSIGNED NOT NULL,
  `borrow_date` date NOT NULL,
  `due_date` date NOT NULL,
  `return_date` date DEFAULT NULL,
  `status` varchar(50) DEFAULT 'borrowed',
  `fine_amount` decimal(10,2) DEFAULT 0.00,
  `fine_paid` tinyint(1) DEFAULT 0,
  `librarian_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_activity_log`
--

CREATE TABLE `lms_activity_log` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL COMMENT 'Teacher or admin ID',
  `user_type` varchar(50) DEFAULT NULL COMMENT 'teacher, admin, student',
  `action` varchar(255) NOT NULL COMMENT 'create_topic, update_topic, upload_resource, etc',
  `object_type` varchar(50) DEFAULT NULL COMMENT 'topic, subtopic, resource, announcement',
  `object_id` int(11) DEFAULT NULL COMMENT 'ID of affected object',
  `description` varchar(500) DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_announcements`
--

CREATE TABLE `lms_announcements` (
  `id` int(11) NOT NULL,
  `teacher_id` int(11) NOT NULL COMMENT 'FK to teachers table',
  `topic_id` int(11) DEFAULT NULL COMMENT 'FK to lms_topics or NULL for general announcement',
  `title` varchar(255) NOT NULL,
  `message` longtext NOT NULL COMMENT 'Rich text message content',
  `visibility` varchar(50) DEFAULT 'public' COMMENT 'public, class-specific, private, draft',
  `is_pinned` tinyint(1) DEFAULT 0,
  `pin_until` timestamp NULL DEFAULT NULL COMMENT 'When to auto-unpin announcement',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_feedback`
--

CREATE TABLE `lms_feedback` (
  `id` int(11) NOT NULL,
  `topic_id` int(11) NOT NULL COMMENT 'FK to lms_topics',
  `subtopic_id` int(11) DEFAULT NULL COMMENT 'FK to lms_subtopics',
  `student_id` int(11) DEFAULT NULL COMMENT 'FK to students table (NULL for anonymous)',
  `teacher_id` int(11) DEFAULT NULL COMMENT 'FK to teachers table (for reply)',
  `comment_type` varchar(50) DEFAULT 'comment' COMMENT 'comment, question, feedback, issue',
  `content` longtext NOT NULL,
  `reply` longtext DEFAULT NULL COMMENT 'Teacher reply to the feedback',
  `is_resolved` tinyint(1) DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `replied_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_resources`
--

CREATE TABLE `lms_resources` (
  `id` int(11) NOT NULL,
  `teacher_id` int(11) NOT NULL COMMENT 'FK to teachers table',
  `topic_id` int(11) DEFAULT NULL COMMENT 'FK to lms_topics (NULL if subtopic-specific)',
  `subtopic_id` int(11) DEFAULT NULL COMMENT 'FK to lms_subtopics (NULL if topic-level)',
  `file_name` varchar(255) NOT NULL COMMENT 'Unique filename on server',
  `original_name` varchar(255) NOT NULL COMMENT 'Original filename uploaded by user',
  `file_path` varchar(500) NOT NULL COMMENT 'Relative path to stored file',
  `file_type` varchar(50) NOT NULL COMMENT 'File extension: pdf, docx, pptx, jpg, mp4, etc',
  `file_size` int(11) NOT NULL COMMENT 'File size in bytes',
  `description` varchar(500) DEFAULT NULL COMMENT 'User-provided description',
  `download_count` int(11) DEFAULT 0 COMMENT 'Number of downloads',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_settings`
--

CREATE TABLE `lms_settings` (
  `id` int(11) NOT NULL,
  `setting_key` varchar(255) NOT NULL,
  `setting_value` longtext DEFAULT NULL COMMENT 'JSON, boolean, or string value',
  `setting_type` varchar(50) DEFAULT 'string' COMMENT 'string, json, boolean, integer',
  `description` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_student_progress`
--

CREATE TABLE `lms_student_progress` (
  `id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL COMMENT 'FK to students table',
  `topic_id` int(11) NOT NULL COMMENT 'FK to lms_topics',
  `subtopic_id` int(11) DEFAULT NULL COMMENT 'FK to lms_subtopics',
  `status` varchar(50) DEFAULT 'not_started' COMMENT 'not_started, in_progress, completed, archived',
  `completion_percentage` int(11) DEFAULT 0 COMMENT 'Percentage of content completed (0-100)',
  `time_spent_seconds` int(11) DEFAULT 0 COMMENT 'Total time spent in seconds',
  `last_accessed` timestamp NULL DEFAULT NULL COMMENT 'Last time student accessed this topic',
  `completed_at` timestamp NULL DEFAULT NULL COMMENT 'When student completed the topic',
  `notes` text DEFAULT NULL COMMENT 'Student notes or highlights',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_subtopics`
--

CREATE TABLE `lms_subtopics` (
  `id` int(11) NOT NULL,
  `topic_id` int(11) NOT NULL COMMENT 'FK to lms_topics',
  `teacher_id` int(11) NOT NULL COMMENT 'FK to teachers table (denormalized for query performance)',
  `title` varchar(255) NOT NULL,
  `description` varchar(500) DEFAULT NULL COMMENT 'Brief description of subtopic',
  `subtopic_number` int(11) NOT NULL COMMENT 'Order/sequence number within the topic',
  `notes` longtext DEFAULT NULL COMMENT 'Rich text lesson notes for this subtopic',
  `view_count` int(11) DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_topics`
--

CREATE TABLE `lms_topics` (
  `id` int(11) NOT NULL,
  `teacher_id` int(11) NOT NULL COMMENT 'FK to teachers table',
  `title` varchar(255) NOT NULL,
  `description` longtext DEFAULT NULL COMMENT 'Topic description/overview',
  `content` longtext DEFAULT NULL COMMENT 'Rich text content of the topic',
  `status` varchar(50) DEFAULT 'draft' COMMENT 'draft, incomplete, published, completed, archived',
  `subject_id` int(11) DEFAULT NULL COMMENT 'Optional: FK to subjects table',
  `notes` longtext DEFAULT NULL COMMENT 'Teacher private notes for this topic',
  `view_count` int(11) DEFAULT 0 COMMENT 'Number of times viewed by students',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `topic_number` int(11) DEFAULT 0 COMMENT 'Order/sequence number for topic ordering'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `lms_topic_classes`
--

CREATE TABLE `lms_topic_classes` (
  `topic_id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `mastercalss`
--

CREATE TABLE `mastercalss` (
  `REGNO` int(11) NOT NULL,
  `Name` varchar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `sex` varchar(400) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `term` varchar(400) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `class` varchar(400) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `active` int(11) NOT NULL,
  `Subjects` varchar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `code` varchar(60) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `weeklytest` varchar(60) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `subject1` varchar(900) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `cod` varchar(60) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `week1` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `maxi` varchar(12) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `mini` varchar(12) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `avgi` int(11) NOT NULL,
  `d4` varchar(12) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `ex` varchar(123) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `tot` decimal(60,0) NOT NULL,
  `rmk` varchar(123) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `okk` varchar(23) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Table structure for table `mentor_remark`
--

CREATE TABLE `mentor_remark` (
  `id` int(11) NOT NULL,
  `class_id` int(11) NOT NULL,
  `session_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `mentor_id` int(11) DEFAULT NULL,
  `mentor_name` varchar(255) DEFAULT NULL,
  `academics` text DEFAULT NULL,
  `social` text DEFAULT NULL,
  `spirit` text DEFAULT NULL,
  `hygiene` text DEFAULT NULL,
  `general` text DEFAULT NULL,
  `remark` text DEFAULT NULL,
  `academics2` text DEFAULT NULL,
  `social2` text DEFAULT NULL,
  `spirit2` text DEFAULT NULL,
  `hygiene2` text DEFAULT NULL,
  `general2` text DEFAULT NULL,
  `remark2` text DEFAULT NULL,
  `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_general_ci;

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

--
-- Table structure for table `messages`
--

CREATE TABLE `messages` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `sender_id` bigint(20) UNSIGNED NOT NULL,
  `receiver_id` bigint(20) UNSIGNED NOT NULL,
  `message` text NOT NULL,
  `is_read` tinyint(1) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `notifications`
--

CREATE TABLE `notifications` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(200) NOT NULL,
  `body` text NOT NULL,
  `target_type` enum('all','class','role','specific_user') DEFAULT 'all' COMMENT 'Who this notification targets',
  `target_class_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'If target_type=class',
  `target_role` enum('admin','teacher','parent','guardian','student') DEFAULT NULL COMMENT 'If target_type=role',
  `target_user_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'If target_type=specific_user',
  `notification_type` enum('announcement','event','urgent','info','reminder') DEFAULT 'info',
  `data_type` varchar(50) DEFAULT NULL COMMENT 'announcement, assignment, fee, etc.',
  `data_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'ID of related announcement/assignment/etc',
  `priority` enum('low','normal','high') DEFAULT 'normal',
  `delivery_status` enum('pending','sent','failed','delivered') DEFAULT 'pending',
  `scheduled_at` datetime DEFAULT NULL COMMENT 'If NULL, send immediately',
  `sent_at` datetime DEFAULT NULL,
  `failure_reason` text DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `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 COMMENT='Push notifications sent to users';

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

--
-- Table structure for table `notification_devices`
--

CREATE TABLE `notification_devices` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `notification_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `fcm_token` varchar(500) NOT NULL,
  `firebase_message_id` varchar(255) DEFAULT NULL,
  `status` enum('sent','failed','invalid_token') NOT NULL DEFAULT 'sent',
  `error_message` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `notification_reads`
--

CREATE TABLE `notification_reads` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `notification_id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `read_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Track which users have read notifications';

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

--
-- Table structure for table `other_payments`
--

CREATE TABLE `other_payments` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `payment_account_id` bigint(20) UNSIGNED DEFAULT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `payment_item_id` bigint(20) UNSIGNED NOT NULL,
  `payment_item_name` varchar(150) NOT NULL,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL,
  `term` varchar(20) DEFAULT NULL,
  `amount_due` decimal(12,2) NOT NULL,
  `amount_paid` decimal(12,2) NOT NULL,
  `payment_date` date NOT NULL,
  `payment_method` varchar(50) DEFAULT NULL,
  `receipt_number` varchar(100) NOT NULL,
  `request_id` varchar(80) DEFAULT NULL,
  `reference` varchar(150) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `recorded_by` bigint(20) UNSIGNED NOT NULL,
  `status` enum('completed','reversed') NOT NULL DEFAULT 'completed',
  `reversed_by` bigint(20) UNSIGNED DEFAULT NULL,
  `reversed_at` datetime DEFAULT NULL,
  `reversal_reason` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `other_payment_items`
--

CREATE TABLE `other_payment_items` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(150) NOT NULL,
  `description` text DEFAULT NULL,
  `default_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `allow_amount_override` tinyint(1) NOT NULL DEFAULT 0,
  `allow_partial_payment` tinyint(1) NOT NULL DEFAULT 0,
  `allow_discounts` tinyint(1) NOT NULL DEFAULT 1,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL,
  `term` varchar(20) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `parent_student`
--

CREATE TABLE `parent_student` (
  `parent_id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `relationship` varchar(50) DEFAULT 'Parent',
  `is_primary` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `results`
--

CREATE TABLE `results` (
  `id` int(11) NOT NULL,
  `ids` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `class_id` bigint(20) UNSIGNED DEFAULT NULL,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL,
  `subject_id` bigint(20) UNSIGNED NOT NULL,
  `subject_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `wk1` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk2` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk3` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk4` decimal(5,2) NOT NULL DEFAULT 0.00,
  `remark_id` bigint(20) UNSIGNED DEFAULT NULL,
  `teacher_comment` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `ca1` decimal(5,2) DEFAULT 0.00,
  `wk6` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk7` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk8` decimal(5,2) NOT NULL DEFAULT 0.00,
  `wk9` decimal(5,2) NOT NULL DEFAULT 0.00,
  `ca2` decimal(5,2) DEFAULT 0.00,
  `st1` decimal(5,2) NOT NULL DEFAULT 0.00,
  `st2` decimal(5,2) NOT NULL DEFAULT 0.00,
  `cat` decimal(5,2) NOT NULL DEFAULT 0.00,
  `exam` decimal(5,2) DEFAULT 0.00,
  `total` decimal(5,2) DEFAULT NULL,
  `grade` char(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `position_in_class` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `pl` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `school_api_sessions`
--

CREATE TABLE `school_api_sessions` (
  `token_hash` char(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `expires_at` datetime NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `school_info`
--

CREATE TABLE `school_info` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `vice_principal` varchar(100) DEFAULT NULL COMMENT 'Name of Vice Principal (if applicable)',
  `school_name` varchar(200) NOT NULL,
  `motto` varchar(255) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `state` varchar(100) DEFAULT NULL,
  `postal_code` varchar(20) DEFAULT NULL,
  `country` varchar(100) DEFAULT NULL,
  `school_email` varchar(150) DEFAULT NULL,
  `phone` varchar(200) DEFAULT NULL,
  `complaints` varchar(300) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `logo_url` varchar(255) DEFAULT NULL,
  `favicon_url` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `principal_primary` varchar(100) DEFAULT NULL COMMENT 'Name of Primary School Principal',
  `principal_secondary` varchar(100) DEFAULT NULL COMMENT 'Name of Secondary School Principal'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `sections`
--

CREATE TABLE `sections` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(255) NOT NULL COMMENT 'Section name e.g., Nursery Academy',
  `stage` varchar(100) NOT NULL COMMENT 'Nursery, Primary, or Secondary',
  `coordinator` varchar(255) DEFAULT NULL COMMENT 'Lead coordinator/tutor name',
  `campus` varchar(100) DEFAULT NULL COMMENT 'Campus location e.g., Main, Annex',
  `status` tinyint(1) DEFAULT 1 COMMENT '1 = Active, 0 = Inactive',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `students`
--

CREATE TABLE `students` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `full_name` varchar(100) NOT NULL,
  `username` varchar(255) DEFAULT NULL,
  `gender` enum('M','F','Other') DEFAULT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `session` varchar(40) NOT NULL,
  `admission_number` varchar(30) NOT NULL,
  `mentor_id` int(11) DEFAULT NULL,
  `mentor` varchar(255) DEFAULT NULL,
  `parent_code` varchar(6) DEFAULT NULL COMMENT '5-6 digit numeric code for parent login',
  `family_id` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `date_of_birth` date DEFAULT NULL,
  `photo_url` varchar(255) DEFAULT NULL,
  `blood_group` varchar(5) DEFAULT NULL,
  `allergies` text DEFAULT NULL,
  `emergency_contact_name` varchar(100) DEFAULT NULL,
  `emergency_contact_phone` varchar(20) DEFAULT NULL,
  `fcm_token` varchar(300) DEFAULT NULL,
  `fcm_token_updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `regno` int(11) NOT NULL,
  `section` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `student_other_payment_accounts`
--

CREATE TABLE `student_other_payment_accounts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `payment_item_id` bigint(20) UNSIGNED NOT NULL,
  `payment_item_name` varchar(150) NOT NULL,
  `session_id` bigint(20) UNSIGNED DEFAULT NULL,
  `term` varchar(20) DEFAULT NULL,
  `amount_due` decimal(12,2) NOT NULL,
  `status` enum('unpaid','partial','paid','cancelled') NOT NULL DEFAULT 'unpaid',
  `created_by` bigint(20) UNSIGNED NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `student_remarks`
--

CREATE TABLE `student_remarks` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `student_id` bigint(20) UNSIGNED NOT NULL,
  `session_id` bigint(20) UNSIGNED NOT NULL,
  `teacher_remark` text DEFAULT NULL,
  `principal_remark` text DEFAULT NULL,
  `class_teacher_remark` text DEFAULT NULL,
  `created_by` bigint(20) UNSIGNED DEFAULT NULL,
  `approved_by` bigint(20) UNSIGNED DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `a` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'AttendanceSS (0-5)',
  `b` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Attentiveness in class (0-5)',
  `c` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Craft, drawing, painting (0-5)',
  `d` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Cooperation spirit (0-5)',
  `e` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Fluency/Elocution (0-5)',
  `f` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Handwriting (0-5)',
  `g` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Honesty (0-5)',
  `h` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Leadership ability (0-5)',
  `i` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Music skills (0-5)',
  `j` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Neatness (0-5)',
  `k` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Organizational ability (0-5)',
  `l` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Politeness (0-5)',
  `m` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Promptness in assignment (0-5)',
  `n` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Punctuality (0-5)',
  `o` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Relationship with staff (0-5)',
  `p` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Relationship with students (0-5)',
  `q` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Reliability (0-5)',
  `r` tinyint(3) UNSIGNED DEFAULT NULL COMMENT 'Responsibility (0-5)',
  `s` int(11) DEFAULT NULL COMMENT 'Self-control',
  `t` int(11) DEFAULT NULL COMMENT 'willingness to learn',
  `u` int(11) DEFAULT NULL,
  `v` int(11) DEFAULT NULL,
  `resumption_date` date DEFAULT NULL COMMENT 'Date students resume for this term',
  `school_closing_date` date DEFAULT NULL COMMENT 'Date school closes for this term',
  `mentor` varchar(300) DEFAULT NULL,
  `teacher_comment` varchar(500) DEFAULT NULL,
  `first_term_comment` varchar(500) DEFAULT NULL,
  `second_term_comment` varchar(500) DEFAULT NULL,
  `abs` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

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

--
-- Table structure for table `subjects`
--

CREATE TABLE `subjects` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `class` varchar(255) DEFAULT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `subject_name` varchar(100) NOT NULL,
  `subject_code` varchar(20) DEFAULT NULL,
  `teacher` varchar(50) DEFAULT NULL,
  `teacher_id` bigint(20) UNSIGNED DEFAULT NULL,
  `credit_hours` decimal(3,1) DEFAULT 1.0,
  `is_compulsory` tinyint(1) DEFAULT 1,
  `description` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `academic_session_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'Links to academic_sessions.id for the term/year this subject applies to',
  `status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '1 = active (offered), 2 = inactive (not offered / deactivated)',
  `assoc_teacher` varchar(500) NOT NULL,
  `grade_type` varchar(10) DEFAULT 'letters',
  `play_class_category` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `timetable`
--

CREATE TABLE `timetable` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `class_id` bigint(20) UNSIGNED NOT NULL,
  `day_of_week` varchar(20) NOT NULL,
  `period_number` tinyint(3) UNSIGNED DEFAULT NULL,
  `subject_id` bigint(20) UNSIGNED NOT NULL,
  `start_time` time NOT NULL,
  `end_time` time NOT NULL,
  `venue` varchar(100) DEFAULT NULL,
  `teacher_id` bigint(20) UNSIGNED DEFAULT NULL,
  `room_number` varchar(20) DEFAULT NULL,
  `session_year` varchar(20) DEFAULT '2025/2026',
  `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;

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `email` varchar(150) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `second_phone` varchar(20) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `date_of_birth` date DEFAULT NULL,
  `password_hash` varchar(2550) NOT NULL,
  `full_name` varchar(100) NOT NULL,
  `gender` enum('Male','Female') DEFAULT NULL,
  `role` enum('parent','guardian','teacher','admin','secretary','bursar','principal','vice_principal','librarian','inventory') NOT NULL DEFAULT 'parent',
  `mentor` varchar(255) DEFAULT NULL,
  `assigned_class` varchar(100) DEFAULT NULL,
  `teacher_role` varchar(200) DEFAULT NULL,
  `photo` varchar(255) DEFAULT NULL,
  `signature` varchar(255) DEFAULT NULL,
  `otp_code` varchar(6) DEFAULT NULL,
  `otp_expires_at` datetime DEFAULT NULL,
  `last_login` datetime DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `fcm_token_updated_at` varchar(300) NOT NULL,
  `fcm_token` varchar(300) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `academic_sessions`
--
ALTER TABLE `academic_sessions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_session_term` (`session_year`,`term`),
  ADD KEY `idx_is_current` (`is_current`);

--
-- Indexes for table `activity_participation`
--
ALTER TABLE `activity_participation`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_activity` (`activity_id`),
  ADD KEY `idx_participation_student` (`student_id`);

--
-- Indexes for table `announcements`
--
ALTER TABLE `announcements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `target_class_id` (`target_class_id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indexes for table `app_settings`
--
ALTER TABLE `app_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `setting_key` (`setting_key`);

--
-- Indexes for table `assignments`
--
ALTER TABLE `assignments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `subject_id` (`subject_id`),
  ADD KEY `teacher_id` (`teacher_id`),
  ADD KEY `idx_status` (`assigned_date`),
  ADD KEY `idx_assignments_class` (`class_id`),
  ADD KEY `idx_assignments_due` (`due_date`);

--
-- Indexes for table `assignment_submissions`
--
ALTER TABLE `assignment_submissions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `assignment_id` (`assignment_id`),
  ADD KEY `graded_by` (`graded_by`),
  ADD KEY `idx_submission_date` (`submission_date`),
  ADD KEY `idx_submissions_student` (`student_id`),
  ADD KEY `idx_submissions_date` (`submission_date`);

--
-- Indexes for table `attendance`
--
ALTER TABLE `attendance`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_student_date` (`student_id`,`attendance_date`),
  ADD KEY `idx_location_type` (`location_type`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_attendance_session_term` (`session_year`,`term`);

--
-- Indexes for table `beva1`
--
ALTER TABLE `beva1`
  ADD PRIMARY KEY (`regno`);

--
-- Indexes for table `bursary_activity`
--
ALTER TABLE `bursary_activity`
  ADD PRIMARY KEY (`id`),
  ADD KEY `action` (`action`,`record_id`),
  ADD KEY `fk_bursary_activity_performed_by` (`performed_by_id`),
  ADD KEY `idx_bursary_activity_action_record` (`action`,`record_id`),
  ADD KEY `idx_bursary_activity_performed_by` (`performed_by_id`);

--
-- Indexes for table `bursary_discounts`
--
ALTER TABLE `bursary_discounts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `is_active` (`is_active`,`student_id`,`applies_to`),
  ADD KEY `session_id` (`session_id`,`class_id`),
  ADD KEY `fk_bursary_discounts_student` (`student_id`),
  ADD KEY `fk_bursary_discounts_class` (`class_id`),
  ADD KEY `fk_bursary_discounts_created_by` (`created_by`),
  ADD KEY `fk_bursary_discount_item` (`other_payment_item_id`),
  ADD KEY `idx_bursary_discount_active` (`is_active`,`student_id`,`applies_to`),
  ADD KEY `idx_bursary_discount_session_class` (`session_id`,`class_id`);

--
-- Indexes for table `bursary_family_discount_allocations`
--
ALTER TABLE `bursary_family_discount_allocations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_family_discount_allocation` (`usage_id`,`fee_id`),
  ADD KEY `idx_family_discount_allocation_fee` (`fee_id`),
  ADD KEY `idx_family_discount_allocation_student` (`student_id`);

--
-- Indexes for table `bursary_family_discount_usage`
--
ALTER TABLE `bursary_family_discount_usage`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_family_discount_once` (`family_id`,`session_id`,`charge_kind`,`scope_item_id`),
  ADD KEY `idx_family_discount_rule` (`discount_id`),
  ADD KEY `idx_family_discount_payment` (`family_payment_id`);

--
-- Indexes for table `bursary_family_payments`
--
ALTER TABLE `bursary_family_payments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `receipt_number` (`receipt_number`),
  ADD KEY `idx_bursary_family_payments_session` (`session_id`,`id`),
  ADD KEY `fk_bursary_family_payment_received_by` (`received_by_id`);

--
-- Indexes for table `bursary_family_payment_lines`
--
ALTER TABLE `bursary_family_payment_lines`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_family_payment_payment` (`payment_id`),
  ADD UNIQUE KEY `uq_family_payment_student` (`family_payment_id`,`student_id`),
  ADD UNIQUE KEY `uq_family_payment_fee` (`family_payment_id`,`fee_id`),
  ADD KEY `fk_family_payment_line_student` (`student_id`),
  ADD KEY `fk_family_payment_line_fee` (`fee_id`);

--
-- Indexes for table `bursary_requests`
--
ALTER TABLE `bursary_requests`
  ADD PRIMARY KEY (`actor_id`,`request_id`);

--
-- Indexes for table `cbt_answers`
--
ALTER TABLE `cbt_answers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_student_question` (`student_id`,`question_id`),
  ADD KEY `test_id` (`test_id`),
  ADD KEY `question_id` (`question_id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `idx_cbt_answers_test_student` (`test_id`,`student_id`),
  ADD KEY `idx_question_order` (`question_order`);

--
-- Indexes for table `cbt_contexts`
--
ALTER TABLE `cbt_contexts`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `cbt_questions`
--
ALTER TABLE `cbt_questions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `test_id` (`test_id`),
  ADD KEY `order_index` (`order_index`),
  ADD KEY `idx_cbt_questions_test_order` (`test_id`,`order_index`);

--
-- Indexes for table `cbt_results`
--
ALTER TABLE `cbt_results`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_test_student` (`test_id`,`student_id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `status` (`status`),
  ADD KEY `idx_cbt_results_test_status` (`test_id`,`status`);

--
-- Indexes for table `cbt_tests`
--
ALTER TABLE `cbt_tests`
  ADD PRIMARY KEY (`id`),
  ADD KEY `teacher_id` (`teacher_id`),
  ADD KEY `subject_id` (`subject_id`),
  ADD KEY `class_id` (`class_id`),
  ADD KEY `session_id` (`session_id`),
  ADD KEY `status` (`status`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `idx_cbt_tests_teacher_status` (`teacher_id`,`status`),
  ADD KEY `idx_cbt_tests_class_subject` (`class_id`,`subject_id`),
  ADD KEY `idx_cbt_tests_start_date` (`start_date`),
  ADD KEY `idx_cbt_tests_end_date` (`end_date`),
  ADD KEY `idx_teacher_subject_session` (`teacher_id`,`subject_id`,`session_id`),
  ADD KEY `idx_sync_status` (`sync_status`),
  ADD KEY `idx_sync_source` (`sync_source`),
  ADD KEY `idx_local_modified_at` (`local_modified_at`);

--
-- Indexes for table `cbt_test_assignments`
--
ALTER TABLE `cbt_test_assignments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_test_student_assignment` (`test_id`,`student_id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `status` (`status`),
  ADD KEY `idx_cbt_assignments_test_status` (`test_id`,`status`),
  ADD KEY `idx_sync_source` (`sync_source`);

--
-- Indexes for table `cbt_test_classes`
--
ALTER TABLE `cbt_test_classes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `test_class_unique` (`test_id`,`class_id`);

--
-- Indexes for table `classes`
--
ALTER TABLE `classes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_class_section` (`class_name`,`section`),
  ADD UNIQUE KEY `uq_classes_name_section` (`class_name`,`section`),
  ADD KEY `fk_classes_teacher` (`class_teacher_id`),
  ADD KEY `section_id` (`section_id`);

--
-- Indexes for table `discipline_records`
--
ALTER TABLE `discipline_records`
  ADD PRIMARY KEY (`id`),
  ADD KEY `reported_by` (`reported_by`),
  ADD KEY `idx_incident_date` (`incident_date`),
  ADD KEY `idx_discipline_student` (`student_id`);

--
-- Indexes for table `events`
--
ALTER TABLE `events`
  ADD PRIMARY KEY (`id`),
  ADD KEY `target_class_id` (`target_class_id`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `idx_event_type` (`event_type`),
  ADD KEY `idx_events_date` (`event_date`),
  ADD KEY `idx_events_type` (`event_type`),
  ADD KEY `idx_events_session_term` (`session_year`,`term`);

--
-- Indexes for table `extracurricular_activities`
--
ALTER TABLE `extracurricular_activities`
  ADD PRIMARY KEY (`id`),
  ADD KEY `coordinator_id` (`coordinator_id`),
  ADD KEY `idx_is_active` (`is_active`),
  ADD KEY `idx_activities_type` (`activity_type`);

--
-- Indexes for table `families`
--
ALTER TABLE `families`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `family_code` (`family_code`),
  ADD KEY `idx_families_active` (`is_active`);

--
-- Indexes for table `fees`
--
ALTER TABLE `fees`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`);

--
-- Indexes for table `feess`
--
ALTER TABLE `feess`
  ADD UNIQUE KEY `regno` (`regno`);

--
-- Indexes for table `fee_charge_details`
--
ALTER TABLE `fee_charge_details`
  ADD PRIMARY KEY (`fee_id`),
  ADD KEY `charge_kind` (`charge_kind`,`category`),
  ADD KEY `fk_fee_charge_details_class` (`class_id`),
  ADD KEY `fk_fee_charge_details_created_by` (`created_by`),
  ADD KEY `idx_fee_charge_kind_category` (`charge_kind`,`category`),
  ADD KEY `idx_fee_charge_class` (`class_id`),
  ADD KEY `idx_fee_charge_created_by` (`created_by`);

--
-- Indexes for table `fee_discounts`
--
ALTER TABLE `fee_discounts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `fee_id` (`fee_id`),
  ADD UNIQUE KEY `uq_fee_discounts_fee` (`fee_id`),
  ADD KEY `fk_fee_discounts_discount` (`discount_id`),
  ADD KEY `fk_fee_discounts_student` (`student_id`),
  ADD KEY `fk_fee_discounts_applied_by` (`applied_by`),
  ADD KEY `idx_fee_discounts_discount` (`discount_id`),
  ADD KEY `idx_fee_discounts_student` (`student_id`),
  ADD KEY `idx_fee_discounts_applied_by` (`applied_by`);

--
-- Indexes for table `fee_items`
--
ALTER TABLE `fee_items`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `fee_payments`
--
ALTER TABLE `fee_payments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_fee_payments_settlement_reference` (`settlement_reference`,`session_id`),
  ADD UNIQUE KEY `uq_fee_payments_receipt_number` (`receipt_number`),
  ADD KEY `idx_fee_payments_student_session` (`student_id`,`session_id`),
  ADD KEY `idx_fee_payments_student` (`student_id`);

--
-- Indexes for table `fee_payment_allocations`
--
ALTER TABLE `fee_payment_allocations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_fee_payment_allocations` (`payment_id`,`fee_id`),
  ADD KEY `idx_fee_payment_allocations_fee` (`fee_id`);

--
-- Indexes for table `fee_payment_details`
--
ALTER TABLE `fee_payment_details`
  ADD PRIMARY KEY (`payment_id`),
  ADD KEY `fk_fee_payment_details_fee` (`fee_id`),
  ADD KEY `fk_fee_payment_details_received_by` (`received_by_id`),
  ADD KEY `idx_fee_payment_details_fee` (`fee_id`),
  ADD KEY `idx_fee_payment_details_received_by` (`received_by_id`);

--
-- Indexes for table `grading_keys`
--
ALTER TABLE `grading_keys`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_range` (`min_score`,`max_score`);

--
-- Indexes for table `grading_playclass`
--
ALTER TABLE `grading_playclass`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `grade` (`grade`);

--
-- Indexes for table `inventory_categories`
--
ALTER TABLE `inventory_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_category_name` (`name`);

--
-- Indexes for table `inventory_issuances`
--
ALTER TABLE `inventory_issuances`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_issuances_issued_by_request` (`issued_by`,`request_id`),
  ADD KEY `date` (`date`,`id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `idx_inventory_issuances_date` (`date`,`id`),
  ADD KEY `idx_inventory_issuances_student` (`student_id`);

--
-- Indexes for table `inventory_issuance_items`
--
ALTER TABLE `inventory_issuance_items`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_issuance_items_issuance_item` (`issuance_id`,`inventory_item_id`),
  ADD UNIQUE KEY `uq_inventory_issuance_items_movement` (`movement_id`),
  ADD KEY `fk_inventory_issuance_items_item` (`inventory_item_id`),
  ADD KEY `idx_inventory_issuance_items_item` (`inventory_item_id`);

--
-- Indexes for table `inventory_items`
--
ALTER TABLE `inventory_items`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_item_sku` (`sku`),
  ADD KEY `idx_inventory_item_category` (`category_id`),
  ADD KEY `idx_inventory_item_active` (`is_active`);

--
-- Indexes for table `inventory_movements`
--
ALTER TABLE `inventory_movements`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_movement_request` (`performed_by_id`,`request_id`),
  ADD KEY `idx_inventory_movement_date` (`date`,`id`),
  ADD KEY `idx_inventory_movement_item` (`item_id`,`id`),
  ADD KEY `idx_inventory_movement_type` (`type`,`date`),
  ADD KEY `idx_inventory_movement_supplier` (`supplier_id`,`date`);

--
-- Indexes for table `inventory_suppliers`
--
ALTER TABLE `inventory_suppliers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_inventory_supplier_name` (`name`);

--
-- Indexes for table `library_books`
--
ALTER TABLE `library_books`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `book_code` (`book_code`),
  ADD UNIQUE KEY `isbn` (`isbn`),
  ADD KEY `idx_category` (`category`),
  ADD KEY `idx_library_books_title` (`book_title`);

--
-- Indexes for table `library_borrowing`
--
ALTER TABLE `library_borrowing`
  ADD PRIMARY KEY (`id`),
  ADD KEY `book_id` (`book_id`),
  ADD KEY `librarian_id` (`librarian_id`),
  ADD KEY `idx_due_date` (`due_date`),
  ADD KEY `idx_borrowing_student` (`student_id`),
  ADD KEY `idx_borrowing_status` (`status`);

--
-- Indexes for table `lms_activity_log`
--
ALTER TABLE `lms_activity_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_user_id` (`user_id`),
  ADD KEY `idx_action` (`action`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Indexes for table `lms_announcements`
--
ALTER TABLE `lms_announcements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `topic_id` (`topic_id`),
  ADD KEY `idx_teacher_id` (`teacher_id`),
  ADD KEY `idx_is_pinned` (`is_pinned`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_visibility` (`visibility`);

--
-- Indexes for table `lms_feedback`
--
ALTER TABLE `lms_feedback`
  ADD PRIMARY KEY (`id`),
  ADD KEY `subtopic_id` (`subtopic_id`),
  ADD KEY `idx_topic_id` (`topic_id`),
  ADD KEY `idx_comment_type` (`comment_type`),
  ADD KEY `idx_is_resolved` (`is_resolved`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Indexes for table `lms_resources`
--
ALTER TABLE `lms_resources`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_topic_id` (`topic_id`),
  ADD KEY `idx_subtopic_id` (`subtopic_id`),
  ADD KEY `idx_teacher_id` (`teacher_id`),
  ADD KEY `idx_file_type` (`file_type`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Indexes for table `lms_settings`
--
ALTER TABLE `lms_settings`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `setting_key` (`setting_key`),
  ADD KEY `idx_key` (`setting_key`);

--
-- Indexes for table `lms_student_progress`
--
ALTER TABLE `lms_student_progress`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_student_topic` (`student_id`,`topic_id`),
  ADD KEY `topic_id` (`topic_id`),
  ADD KEY `subtopic_id` (`subtopic_id`),
  ADD KEY `idx_student_id` (`student_id`),
  ADD KEY `idx_status` (`status`),
  ADD KEY `idx_completed_at` (`completed_at`);

--
-- Indexes for table `lms_subtopics`
--
ALTER TABLE `lms_subtopics`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_subtopic_order` (`topic_id`,`subtopic_number`),
  ADD KEY `idx_topic_id` (`topic_id`),
  ADD KEY `idx_teacher_id` (`teacher_id`),
  ADD KEY `idx_created_at` (`created_at`);

--
-- Indexes for table `lms_topics`
--
ALTER TABLE `lms_topics`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_teacher_id` (`teacher_id`),
  ADD KEY `idx_status` (`status`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_topic_number` (`teacher_id`,`topic_number`);

--
-- Indexes for table `lms_topic_classes`
--
ALTER TABLE `lms_topic_classes`
  ADD PRIMARY KEY (`topic_id`,`class_id`),
  ADD KEY `idx_topic_class` (`topic_id`,`class_id`);

--
-- Indexes for table `mastercalss`
--
ALTER TABLE `mastercalss`
  ADD PRIMARY KEY (`avgi`);

--
-- Indexes for table `mentor_remark`
--
ALTER TABLE `mentor_remark`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_mentor_remark` (`class_id`,`session_id`,`student_id`,`mentor_id`),
  ADD KEY `idx_mentor_remark_student` (`student_id`),
  ADD KEY `idx_mentor_remark_mentor` (`mentor_id`),
  ADD KEY `idx_mentor_remark_class_session` (`class_id`,`session_id`);

--
-- Indexes for table `messages`
--
ALTER TABLE `messages`
  ADD PRIMARY KEY (`id`),
  ADD KEY `sender_id` (`sender_id`),
  ADD KEY `receiver_id` (`receiver_id`);

--
-- Indexes for table `notifications`
--
ALTER TABLE `notifications`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_target_type` (`target_type`),
  ADD KEY `idx_target_class_id` (`target_class_id`),
  ADD KEY `idx_delivery_status` (`delivery_status`),
  ADD KEY `idx_created_at` (`created_at`),
  ADD KEY `idx_scheduled_at` (`scheduled_at`),
  ADD KEY `idx_data` (`data_type`,`data_id`);

--
-- Indexes for table `notification_devices`
--
ALTER TABLE `notification_devices`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_notification` (`notification_id`),
  ADD KEY `idx_student` (`student_id`),
  ADD KEY `idx_status` (`status`);

--
-- Indexes for table `notification_reads`
--
ALTER TABLE `notification_reads`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_notification_user` (`notification_id`,`user_id`),
  ADD KEY `idx_read_at` (`read_at`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `other_payments`
--
ALTER TABLE `other_payments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_other_payment_receipt` (`receipt_number`),
  ADD UNIQUE KEY `uq_other_payment_request` (`recorded_by`,`request_id`),
  ADD KEY `idx_other_payments_student` (`student_id`),
  ADD KEY `idx_other_payments_class` (`class_id`),
  ADD KEY `idx_other_payments_item` (`payment_item_id`),
  ADD KEY `idx_other_payments_date` (`payment_date`),
  ADD KEY `idx_other_payments_account` (`payment_account_id`);

--
-- Indexes for table `other_payment_items`
--
ALTER TABLE `other_payment_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_other_payment_items_active` (`is_active`),
  ADD KEY `idx_other_payment_items_session` (`session_id`),
  ADD KEY `idx_other_payment_items_name` (`name`);

--
-- Indexes for table `parent_student`
--
ALTER TABLE `parent_student`
  ADD PRIMARY KEY (`parent_id`,`student_id`),
  ADD KEY `student_id` (`student_id`);

--
-- Indexes for table `results`
--
ALTER TABLE `results`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `school_api_sessions`
--
ALTER TABLE `school_api_sessions`
  ADD PRIMARY KEY (`token_hash`),
  ADD KEY `idx_api_sessions_user` (`user_id`),
  ADD KEY `idx_api_sessions_expiry` (`expires_at`);

--
-- Indexes for table `school_info`
--
ALTER TABLE `school_info`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `sections`
--
ALTER TABLE `sections`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_stage` (`stage`),
  ADD KEY `idx_campus` (`campus`);

--
-- Indexes for table `students`
--
ALTER TABLE `students`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `parent_code` (`parent_code`),
  ADD KEY `idx_parent_code` (`parent_code`),
  ADD KEY `admission_number` (`admission_number`) USING BTREE,
  ADD KEY `idx_students_family_id` (`family_id`);

--
-- Indexes for table `student_other_payment_accounts`
--
ALTER TABLE `student_other_payment_accounts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_sopa_student` (`student_id`),
  ADD KEY `idx_sopa_item` (`payment_item_id`),
  ADD KEY `idx_sopa_class` (`class_id`);

--
-- Indexes for table `student_remarks`
--
ALTER TABLE `student_remarks`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_student_session` (`student_id`,`session_id`),
  ADD KEY `session_id` (`session_id`),
  ADD KEY `created_by` (`created_by`),
  ADD KEY `approved_by` (`approved_by`);

--
-- Indexes for table `subjects`
--
ALTER TABLE `subjects`
  ADD PRIMARY KEY (`id`),
  ADD KEY `teacher_id` (`teacher_id`),
  ADD KEY `idx_class` (`class_id`),
  ADD KEY `idx_subject_name` (`subject_name`),
  ADD KEY `idx_subjects_class` (`class_id`),
  ADD KEY `idx_session_status` (`academic_session_id`,`status`),
  ADD KEY `idx_subjects_class_session_name` (`class_id`,`academic_session_id`,`subject_name`);

--
-- Indexes for table `timetable`
--
ALTER TABLE `timetable`
  ADD PRIMARY KEY (`id`),
  ADD KEY `subject_id` (`subject_id`),
  ADD KEY `teacher_id` (`teacher_id`),
  ADD KEY `idx_class` (`class_id`),
  ADD KEY `idx_timetable_class` (`class_id`),
  ADD KEY `idx_timetable_day` (`day_of_week`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_role_fcm` (`role`),
  ADD KEY `idx_assigned_class_fcm` (`assigned_class`);

--
-- AUTO_INCREMENT for dumped tables
--

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

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

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

--
-- AUTO_INCREMENT for table `app_settings`
--
ALTER TABLE `app_settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

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

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

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

--
-- AUTO_INCREMENT for table `cbt_answers`
--
ALTER TABLE `cbt_answers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cbt_questions`
--
ALTER TABLE `cbt_questions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cbt_results`
--
ALTER TABLE `cbt_results`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cbt_tests`
--
ALTER TABLE `cbt_tests`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cbt_test_assignments`
--
ALTER TABLE `cbt_test_assignments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `cbt_test_classes`
--
ALTER TABLE `cbt_test_classes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

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

--
-- AUTO_INCREMENT for table `fee_items`
--
ALTER TABLE `fee_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

--
-- AUTO_INCREMENT for table `grading_playclass`
--
ALTER TABLE `grading_playclass`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

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

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

--
-- AUTO_INCREMENT for table `lms_activity_log`
--
ALTER TABLE `lms_activity_log`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_announcements`
--
ALTER TABLE `lms_announcements`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_feedback`
--
ALTER TABLE `lms_feedback`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_resources`
--
ALTER TABLE `lms_resources`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_settings`
--
ALTER TABLE `lms_settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_student_progress`
--
ALTER TABLE `lms_student_progress`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_subtopics`
--
ALTER TABLE `lms_subtopics`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `lms_topics`
--
ALTER TABLE `lms_topics`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `mastercalss`
--
ALTER TABLE `mastercalss`
  MODIFY `avgi` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `mentor_remark`
--
ALTER TABLE `mentor_remark`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

--
-- AUTO_INCREMENT for table `results`
--
ALTER TABLE `results`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

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

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

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

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

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

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

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

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

--
-- Constraints for dumped tables
--

--
-- Constraints for table `activity_participation`
--
ALTER TABLE `activity_participation`
  ADD CONSTRAINT `activity_participation_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `activity_participation_ibfk_2` FOREIGN KEY (`activity_id`) REFERENCES `extracurricular_activities` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `announcements`
--
ALTER TABLE `announcements`
  ADD CONSTRAINT `announcements_ibfk_1` FOREIGN KEY (`target_class_id`) REFERENCES `classes` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `announcements_ibfk_2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `assignments`
--
ALTER TABLE `assignments`
  ADD CONSTRAINT `assignments_ibfk_1` FOREIGN KEY (`class_id`) REFERENCES `classes` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `assignments_ibfk_2` FOREIGN KEY (`subject_id`) REFERENCES `subjects` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `assignments_ibfk_3` FOREIGN KEY (`teacher_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `assignment_submissions`
--
ALTER TABLE `assignment_submissions`
  ADD CONSTRAINT `assignment_submissions_ibfk_1` FOREIGN KEY (`assignment_id`) REFERENCES `assignments` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `assignment_submissions_ibfk_2` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `assignment_submissions_ibfk_3` FOREIGN KEY (`graded_by`) REFERENCES `users` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `attendance`
--
ALTER TABLE `attendance`
  ADD CONSTRAINT `attendance_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `bursary_activity`
--
ALTER TABLE `bursary_activity`
  ADD CONSTRAINT `fk_bursary_activity_performed_by` FOREIGN KEY (`performed_by_id`) REFERENCES `users` (`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 */;
