<?php

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

return new class extends Migration
{
    public function up()
    {
        // rename tabel berita -> informasi
        Schema::rename('berita', 'informasi');

        Schema::table('informasi', function (Blueprint $table) {

            // ubah nama primary key
            $table->renameColumn('id_berita', 'id_informasi');

            // ubah nama kolom
            $table->renameColumn('judul_berita', 'judul');
            $table->renameColumn('isi_berita', 'isi');
            $table->renameColumn('tanggal_berita', 'tanggal');
            $table->renameColumn('gambar_berita', 'gambar');

            // tambah kategori
            $table->enum('kategori', ['berita', 'pengumuman'])->after('judul');
        });
    }

    public function down()
    {
        Schema::rename('informasi', 'berita');

        Schema::table('berita', function (Blueprint $table) {

            $table->renameColumn('id_informasi', 'id_berita');

            $table->renameColumn('judul', 'judul_berita');
            $table->renameColumn('isi', 'isi_berita');
            $table->renameColumn('tanggal', 'tanggal_berita');
            $table->renameColumn('gambar', 'gambar_berita');

            $table->dropColumn('kategori');
        });
    }
};
