<?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 `student_medical_conditions` (
`id` int NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `condition_name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

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

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

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `student_medical_conditions`
  ADD CONSTRAINT `student_medical_conditions_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`id`) ON DELETE CASCADE;
SQL
        );

    }

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