<?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::hasColumn('admin_permissions', 'status')) {
            DB::statement('ALTER TABLE admin_permissions ADD COLUMN status TINYINT NOT NULL DEFAULT 1 COMMENT \'状态：0-禁用 1-启用\' AFTER app_id');
        }

        DB::table('admin_permissions')->whereNull('status')->update(['status' => 1]);
    }

    public function down(): void
    {
        if (Schema::hasColumn('admin_permissions', 'status')) {
            DB::statement('ALTER TABLE admin_permissions DROP COLUMN status');
        }
    }
};
