<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `attendance_record` (
`id` int UNSIGNED NOT NULL,
  `class_section_id` int NOT NULL,
  `student_id` int NOT NULL,
  `school_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `total_absence` int NOT NULL DEFAULT '0',
  `total_late` int NOT NULL DEFAULT '0',
  `total_presence` int NOT NULL DEFAULT '0',
  `total_attendance` int NOT NULL DEFAULT '0',
  `semester` varchar(25) COLLATE utf8mb4_general_ci NOT NULL,
  `school_year` varchar(9) COLLATE utf8mb4_general_ci NOT NULL,
  `modified_by` int DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `attendance_record`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_student_id` (`student_id`),
  ADD KEY `idx_class_section_id` (`class_section_id`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `attendance_record`
  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;
SQL
        );

    }

    public function down(): void
    {
        Schema::dropIfExists('attendance_record');
    }
};