<?php

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

/**
 * A machine that is running on less CPU or RAM than its contract now says.
 *
 * Proxmox takes a new `cores`/`memory` on a running guest into the VM's
 * configuration and applies it at the next cold boot — nothing in this codebase
 * turns CPU or memory hotplug on, so a plan change that grows a live machine
 * changes what it WILL have, not what it has. There are only two honest things
 * to do with that: reboot the customer's machine as a side effect of a purchase,
 * or say so. This column is the saying so.
 *
 * Set by the plan-change pipeline's resize step, read by the console's instance
 * list and by the customer's own cloud page. Cleared by the same step the next
 * time it finds the machine stopped, because a stopped machine takes its new
 * size the moment it starts.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('instances', function (Blueprint $table) {
            $table->timestamp('restart_required_since')->nullable()->after('cores');
        });
    }

    public function down(): void
    {
        Schema::table('instances', function (Blueprint $table) {
            $table->dropColumn('restart_required_since');
        });
    }
};
