<?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 `competition_scores` (
`id` int UNSIGNED NOT NULL,
  `competition_id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `class_section_id` int DEFAULT NULL,
  `score` decimal(6,2) NOT NULL DEFAULT '0.00',
  `notes` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `competition_scores`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `competition_id_student_id_class_section_id` (`competition_id`,`student_id`,`class_section_id`),
  ADD KEY `competition_id` (`competition_id`),
  ADD KEY `student_id` (`student_id`),
  ADD KEY `class_section_id` (`class_section_id`);
SQL
        );

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

    }

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