<?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_allergies` (
`id` int NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `allergy` 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_allergies`
  ADD PRIMARY KEY (`id`),
  ADD KEY `student_id` (`student_id`);
SQL
        );

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

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

    }

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