<?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
    {
        if (! Schema::hasTable('song_groups')) {
            return;
        }

        if (DB::table('song_groups')->count() === 0) {
            return;
        }

        DB::statement('PRAGMA foreign_keys = OFF');

        try {
            DB::table('song_arrangement_groups')->delete();
            DB::table('song_arrangements')->delete();
            DB::table('song_slides')->delete();
            DB::table('song_groups')->delete();
            DB::table('service_songs')->delete();
            DB::table('songs')->delete();
        } finally {
            DB::statement('PRAGMA foreign_keys = ON');
        }
    }

    public function down(): void
    {
        // Data is unrecoverable — intentional no-op
    }
};
