feat(rescue): add global catalog schema

go
codex 3 weeks ago
parent d2a00767b2
commit 7fd9fa44ca

@ -8,14 +8,16 @@ use App\Services\Config;
/** Initializes only the clean-break PHP business and Agent log schemas. */
final class CloudSetup
{
private const SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts';
private const SCHEMA_VERSION = 'go-agent-wss-v17-rescue-artifacts';
private const MAIN_TABLES = [
'cloud_regions', 'cloud_network_lines', 'cloud_resource_pools',
'cloud_hosts', 'cloud_host_agents',
'cloud_host_storage_configurations', 'cloud_templates',
'cloud_template_artifacts', 'cloud_template_replicas',
'cloud_user_isos',
'cloud_user_iso_replicas', 'cloud_rescue_template_deletions',
'cloud_user_iso_replicas', 'cloud_rescue_templates',
'cloud_rescue_template_artifacts', 'cloud_rescue_template_replicas',
'cloud_rescue_template_deletions',
'cloud_rescue_template_imports', 'cloud_upload_staging',
'cloud_host_resource_pool_memberships',
'cloud_host_network_attachments', 'cloud_public_ip_pools',
@ -65,6 +67,28 @@ final class CloudSetup
'observed_generation_token', 'observed_image_bytes',
'observed_sha256', 'last_verified_at', 'created_at', 'updated_at',
],
'cloud_rescue_templates' => [
'id', 'name', 'size_bytes', 'sha256', 'revision',
'generation_token', 'state', 'active_job_id',
'created_at', 'updated_at',
],
'cloud_rescue_template_artifacts' => [
'template_id', 'storage_revision', 'sealed_storage_runtime',
'object_key', 'object_version_id', 'object_etag', 'size_bytes',
'sha256', 'state', 'error_code', 'delete_operation_id',
'delete_generation', 'delete_cycle_attempts',
'delete_presence_confirmations', 'delete_last_checked_at',
'delete_next_check_at', 'delete_attention_at', 'verified_at',
'created_at', 'updated_at',
],
'cloud_rescue_template_replicas' => [
'host_id', 'template_id', 'revision', 'generation_token',
'state', 'size_bytes', 'sha256', 'operation_id', 'job_id',
'error_code', 'observed_state', 'observed_revision',
'observed_generation_token', 'observed_size_bytes',
'observed_sha256', 'last_verified_at', 'cleanup_resolved_at',
'created_at', 'updated_at',
],
'cloud_offers' => [
'backup_price',
],
@ -307,6 +331,20 @@ final class CloudSetup
'PRIMARY', 'cloud_template_replica_ready',
'cloud_template_replica_observed',
],
'cloud_rescue_templates' => [
'PRIMARY', 'cloud_rescue_template_generation',
'cloud_rescue_template_catalog',
],
'cloud_rescue_template_artifacts' => [
'PRIMARY', 'cloud_rescue_artifact_object',
'cloud_rescue_artifact_state',
'cloud_rescue_artifact_delete_due',
],
'cloud_rescue_template_replicas' => [
'PRIMARY', 'cloud_rescue_replica_ready',
'cloud_rescue_replica_observed',
'cloud_rescue_replica_cleanup',
],
'cloud_host_vpc_transports' => [
'PRIMARY', 'cloud_host_vpc_transport_operation',
'cloud_host_vpc_transport_state',

@ -0,0 +1,20 @@
<?php
namespace App\Models;
/** Global immutable rescue ISO catalog entry and retirement tombstone. */
final class CloudRescueTemplate extends Model
{
protected $connection = 'default';
protected $table = 'cloud_rescue_templates';
protected $primaryKey = 'id';
public $incrementing = false;
protected $keyType = 'string';
protected $casts = [
'size_bytes' => 'int',
'revision' => 'int',
'active_job_id' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,27 @@
<?php
namespace App\Models;
/** Canonical immutable object behind one rescue ISO generation. */
final class CloudRescueTemplateArtifact extends Model
{
protected $connection = 'default';
protected $table = 'cloud_rescue_template_artifacts';
protected $primaryKey = 'template_id';
public $incrementing = false;
protected $keyType = 'string';
protected $hidden = ['sealed_storage_runtime'];
protected $casts = [
'storage_revision' => 'int',
'size_bytes' => 'int',
'delete_generation' => 'int',
'delete_cycle_attempts' => 'int',
'delete_presence_confirmations' => 'int',
'delete_last_checked_at' => 'int',
'delete_next_check_at' => 'int',
'delete_attention_at' => 'int',
'verified_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,25 @@
<?php
namespace App\Models;
/** Host-local exact rescue ISO copy and retirement cleanup debt. */
final class CloudRescueTemplateReplica extends Model
{
protected $connection = 'default';
protected $table = 'cloud_rescue_template_replicas';
public $incrementing = false;
protected $primaryKey = 'template_id';
protected $keyType = 'string';
protected $casts = [
'host_id' => 'int',
'revision' => 'int',
'size_bytes' => 'int',
'job_id' => 'int',
'observed_revision' => 'int',
'observed_size_bytes' => 'int',
'last_verified_at' => 'int',
'cleanup_resolved_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -421,6 +421,81 @@ CREATE TABLE cloud_user_iso_replicas (
KEY cloud_user_iso_replica_operation (operation_id, state)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- PHP owns one global immutable rescue ISO generation. The retired row is a
-- durable tombstone: it prevents the same generation from becoming usable
-- again while object-storage or offline-host cleanup debt is still present.
CREATE TABLE cloud_rescue_templates (
id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
name VARCHAR(64) NOT NULL,
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'preparing',
active_job_id BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_rescue_template_generation (generation_token),
KEY cloud_rescue_template_catalog (state, name, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- The canonical object is frozen to the object-storage runtime used when it
-- was published. Deletion state remains after logical retirement so a lost
-- provider response can be reconciled without reviving the catalog entry.
CREATE TABLE cloud_rescue_template_artifacts (
template_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
storage_revision BIGINT UNSIGNED NOT NULL,
sealed_storage_runtime LONGTEXT NOT NULL,
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
size_bytes BIGINT UNSIGNED NOT NULL,
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
delete_operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
delete_cycle_attempts INT UNSIGNED NOT NULL DEFAULT 0,
delete_presence_confirmations INT UNSIGNED NOT NULL DEFAULT 0,
delete_last_checked_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_rescue_artifact_object (object_key),
KEY cloud_rescue_artifact_state (state, verified_at, template_id),
KEY cloud_rescue_artifact_delete_due (state, delete_next_check_at, template_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Host copies are disposable, but their cleanup rows survive retirement.
-- Only an active row matching revision, generation, size and SHA is usable.
CREATE TABLE cloud_rescue_template_replicas (
host_id BIGINT UNSIGNED NOT NULL,
template_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
revision BIGINT UNSIGNED NOT NULL,
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
job_id BIGINT UNSIGNED DEFAULT NULL,
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
observed_state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
observed_generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
observed_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
observed_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
cleanup_resolved_at BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (host_id, template_id),
KEY cloud_rescue_replica_ready (template_id, state, revision, host_id),
KEY cloud_rescue_replica_observed (observed_state, last_verified_at, host_id),
KEY cloud_rescue_replica_cleanup (state, cleanup_resolved_at, host_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Rescue templates are host-local, but deletion is still a durable,
-- single-dispatch Agent operation. Its terminal tombstone forbids replay.
CREATE TABLE cloud_rescue_template_deletions (

@ -22,7 +22,7 @@ $assert(stripos($schema, 'compatibility import') === false
$assert(!preg_match('/\bengine_[A-Za-z0-9_]*\b/', $schema),
'cloud.sql retained an engine-prefixed identifier.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts'")
"SCHEMA_VERSION = 'go-agent-wss-v17-rescue-artifacts'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'Outbound Agent schema must reject the incompatible earlier Go database.');
$assert(str_contains($schema,
@ -34,7 +34,9 @@ $assert(str_contains($schema,
'Fresh automatic-backup subscriptions must default to UTC with a state revision.');
foreach (['cloud_host_agents', 'cloud_templates', 'cloud_template_artifacts',
'cloud_template_replicas', 'cloud_hosts', 'cloud_instances',
'cloud_template_replicas', 'cloud_rescue_templates',
'cloud_rescue_template_artifacts', 'cloud_rescue_template_replicas',
'cloud_hosts', 'cloud_instances',
'cloud_orders', 'cloud_invoices', 'cloud_jobs',
'cloud_agent_completion_events', 'cloud_console_tickets',
'cloud_rescue_template_imports', 'cloud_instance_backups',

@ -0,0 +1,64 @@
<?php
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
if (!is_string($schema) || !is_string($setup)) {
throw new RuntimeException('Rescue catalog schema sources are unreadable.');
}
foreach ([
'cloud_rescue_templates',
'cloud_rescue_template_artifacts',
'cloud_rescue_template_replicas',
] as $table) {
$assert(str_contains($schema, 'CREATE TABLE ' . $table . ' ('),
'Missing global rescue catalog table: ' . $table);
$assert(str_contains($setup, "'" . $table . "'"),
'CloudSetup does not require global rescue table: ' . $table);
}
$catalog = preg_match(
'/CREATE TABLE cloud_rescue_templates \((.*?)\n\) ENGINE=/s',
$schema,
$catalogMatch
) === 1 ? $catalogMatch[1] : '';
$artifact = preg_match(
'/CREATE TABLE cloud_rescue_template_artifacts \((.*?)\n\) ENGINE=/s',
$schema,
$artifactMatch
) === 1 ? $artifactMatch[1] : '';
$replica = preg_match(
'/CREATE TABLE cloud_rescue_template_replicas \((.*?)\n\) ENGINE=/s',
$schema,
$replicaMatch
) === 1 ? $replicaMatch[1] : '';
$assert($catalog !== ''
&& str_contains($catalog, 'generation_token CHAR(32)')
&& str_contains($catalog, 'revision BIGINT UNSIGNED')
&& str_contains($catalog, 'active_job_id BIGINT UNSIGNED'),
'Rescue master does not retain immutable identity and active-job fencing.');
$assert($artifact !== ''
&& str_contains($artifact, 'sealed_storage_runtime LONGTEXT')
&& str_contains($artifact, 'object_version_id VARCHAR(1024)')
&& str_contains($artifact, 'delete_presence_confirmations')
&& str_contains($artifact, 'delete_attention_at'),
'Rescue artifact cannot reconcile exact provider deletion effects.');
$assert($replica !== ''
&& str_contains($replica, 'observed_generation_token CHAR(32)')
&& str_contains($replica, 'observed_sha256 CHAR(64)')
&& str_contains($replica, 'cleanup_resolved_at BIGINT UNSIGNED'),
'Rescue replica cannot prove exact identity or retain cleanup debt.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v17-rescue-artifacts'")
&& str_contains($setup, "'cloud_rescue_artifact_delete_due'")
&& str_contains($setup, "'cloud_rescue_replica_cleanup'"),
'CloudSetup version or rescue catalog indexes are incomplete.');
echo "Global rescue catalog schema contract passed.\n";

@ -101,7 +101,7 @@ $assert(str_contains($jobs, 'vpc_id BIGINT UNSIGNED DEFAULT NULL')
'Cloud jobs cannot be correlated to VPC or VPC-port work.');
$assert(str_contains($setup,
"private const SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts'")
"private const SCHEMA_VERSION = 'go-agent-wss-v17-rescue-artifacts'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup,

Loading…
Cancel
Save