<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::rename('entry_galleries', 'galleries');

        Schema::table('galleries', function (Blueprint $table) {
            $table->string('galleryable_type')->default('App\\Models\\Entry')
                ->after('id');

            $table->renameColumn('entry_id', 'galleryable_id');

            $table->index(['galleryable_type', 'galleryable_id']);

        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('galleries', function (Blueprint $table) {
            $table->dropColumn('galleryable_type');
            $table->renameColumn('galleryable_id', 'entry_id');
            $table->dropIndex(['galleryable_type', 'galleryable_id']);
        });

        Schema::rename('galleries', 'entry_galleries');
    }
};
