<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Import the base SQL file if tables don't exist yet
        if (!Schema::hasTable('admin')) {
            $sqlPath = base_path('jurusan_otomotif.sql');
            if (file_exists($sqlPath)) {
                $sql = file_get_contents($sqlPath);
                // Remove comment lines and transactions if any, or run unprepared directly
                DB::unprepared($sql);
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('siswa');
        Schema::dropIfExists('pkl');
        Schema::dropIfExists('prestasi');
        Schema::dropIfExists('pengumuman');
        Schema::dropIfExists('jadwal_praktik');
        Schema::dropIfExists('guru');
        Schema::dropIfExists('galeri');
        Schema::dropIfExists('berita');
        Schema::dropIfExists('alumni');
        Schema::dropIfExists('petugas');
        Schema::dropIfExists('admin');
        Schema::dropIfExists('profil_jurusan');
    }
};
