<?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 `students` (
`id` int UNSIGNED NOT NULL,
  `school_id` char(100) COLLATE utf8mb4_general_ci NOT NULL,
  `firstname` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `lastname` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `dob` date DEFAULT NULL,
  `age` int NOT NULL,
  `gender` varchar(10) COLLATE utf8mb4_general_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `registration_grade` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_new` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1 = new student, 0 = returning student',
  `photo_consent` tinyint(1) NOT NULL,
  `parent_id` int NOT NULL,
  `registration_date` datetime DEFAULT NULL,
  `tuition_paid` tinyint(1) NOT NULL DEFAULT '0',
  `rfid_tag` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `semester` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `year_of_registration` varchar(25) COLLATE utf8mb4_general_ci NOT NULL,
  `school_year` varchar(9) COLLATE utf8mb4_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

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

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

    }

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