<?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('kylin_game_save_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('save_id')->constrained('kylin_game_saves')->cascadeOnDelete()->comment('存档 ID');
            $table->json('data')->comment('历史存档数据快照');
            $table->unsignedInteger('version')->comment('版本号');
            $table->string('action', 20)->comment('操作类型:create/update/conflict_resolve/delete');
            $table->timestamps();
            $table->softDeletes();

            $table->index('save_id');
            $table->index('action');
            $table->index('created_at');
        });
    }

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