<?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('metric_samples', function (Blueprint $table) {
            $table->id();
            $table->foreignId('server_id')->constrained()->cascadeOnDelete();
            $table->unsignedTinyInteger('cpu')->default(0);
            $table->unsignedTinyInteger('mem')->default(0);
            $table->unsignedTinyInteger('disk')->default(0);
            $table->decimal('load', 6, 2)->default(0);
            $table->timestamp('sampled_at')->index();
            $table->index(['server_id', 'sampled_at']);
        });
    }

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