<?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 `midterm_exam` (
`id` int UNSIGNED NOT NULL,
  `student_id` int NOT NULL,
  `school_id` char(36) NOT NULL,
  `class_section_id` int DEFAULT NULL,
  `updated_by` int NOT NULL,
  `score` float DEFAULT NULL,
  `comment` text,
  `semester` varchar(25) NOT NULL DEFAULT 'Fall',
  `school_year` varchar(9) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `migrations`
--


CREATE TABLE `migrations` (

`id` int UNSIGNED NOT NULL,

  `version` varchar(255) NOT NULL,

  `class` varchar(255) NOT NULL,

  `group` varchar(255) NOT NULL,

  `namespace` varchar(255) NOT NULL,

  `time` int NOT NULL,

  `batch` int UNSIGNED NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

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

--
-- Table structure for table `missing_score_overrides`
--


CREATE TABLE `missing_score_overrides` (

`id` int UNSIGNED NOT NULL,

  `student_id` int UNSIGNED NOT NULL,

  `class_section_id` int UNSIGNED NOT NULL,

  `semester` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,

  `school_year` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,

  `item_type` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL,

  `item_index` int DEFAULT NULL,

  `is_allowed` tinyint(1) NOT NULL DEFAULT '0',

  `updated_by` int UNSIGNED DEFAULT NULL,

  `created_at` datetime DEFAULT NULL,

  `updated_at` datetime DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `midterm_exam`
  ADD PRIMARY KEY (`id`);
SQL
        );

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

    }

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