<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('periksa', function (Blueprint $table) {
            if (!Schema::hasColumn('periksa', 'tanggalregis')) {
                $table->date('tanggalregis')->nullable()->after('tgladendum');
            }
            if (!Schema::hasColumn('periksa', 'tanggalsampel')) {
                $table->date('tanggalsampel')->nullable()->after('tanggalregis');
            }
            if (!Schema::hasColumn('periksa', 'pengambilan')) {
                $table->string('pengambilan', 255)->nullable()->after('diagnosa2');
            }
        });
        Schema::table('pertumkolomni', function (Blueprint $table) {
            if (!Schema::hasColumn('pertumkolomni', 'keterangan')) {
                $table->text('keterangan')->nullable()->after('tindaklanjut');
            }
        });
    }

    public function down(): void
    {
        Schema::table('periksa', function (Blueprint $table) {
            if (Schema::hasColumn('periksa', 'tanggalregis')) {
                $table->dropColumn('tanggalregis');
            }
            if (Schema::hasColumn('periksa', 'tanggalsampel')) {
                $table->dropColumn('tanggalsampel');
            }
            if (Schema::hasColumn('periksa', 'pengambilan')) {
                $table->dropColumn('pengambilan');
            }
        });
        Schema::table('pertumkolomni', function (Blueprint $table) {
            if (Schema::hasColumn('pertumkolomni', 'keterangan')) {
                $table->dropColumn('keterangan');
            }
        });
    }
};
