<?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 `promotion_queue` (
`id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `from_class_section_id` int UNSIGNED DEFAULT NULL,
  `to_class_id` int UNSIGNED NOT NULL,
  `to_class_section_id` int UNSIGNED DEFAULT NULL,
  `school_year_from` varchar(9) NOT NULL,
  `school_year_to` varchar(9) NOT NULL,
  `status` enum('queued','assigned','applied','cancelled') NOT NULL DEFAULT 'queued',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int UNSIGNED DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `promotion_queue`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uq_student_year_to` (`student_id`,`school_year_to`),
  ADD KEY `to_class_id` (`to_class_id`);
SQL
        );

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

    }

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