<?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::create('app_backups', function (Blueprint $table) {
            $table->id();
            $table->string('app_id', 100)->comment('应用ID');
            $table->string('app_name', 100)->comment('应用名称');
            $table->string('app_version', 50)->default('')->comment('备份时应用版本');
            $table->string('backup_type', 20)->default('full')->comment('备份类型：full=完整备份');
            $table->string('file_path', 500)->default('')->comment('备份文件路径');
            $table->bigInteger('file_size')->default(0)->comment('备份文件大小(字节)');
            $table->json('db_tables')->nullable()->comment('备份的数据库表列表');
            $table->tinyInteger('status')->default(1)->comment('状态：0=失败 1=成功');
            $table->unsignedBigInteger('operator_id')->default(0)->comment('操作人ID');
            $table->string('error_message', 500)->default('')->comment('错误信息');
            $table->dateTime('create_time')->nullable()->comment('创建时间');
            $table->dateTime('update_time')->nullable()->comment('更新时间');

            $table->index('app_id');
            $table->index('status');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('app_backups');
    }
};
