diff --git a/web/app/Command/CloudSetup.php b/web/app/Command/CloudSetup.php index 68e25d5c..078e32c7 100644 --- a/web/app/Command/CloudSetup.php +++ b/web/app/Command/CloudSetup.php @@ -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', diff --git a/web/app/Models/CloudRescueTemplate.php b/web/app/Models/CloudRescueTemplate.php new file mode 100644 index 00000000..b9aa12cc --- /dev/null +++ b/web/app/Models/CloudRescueTemplate.php @@ -0,0 +1,20 @@ + 'int', + 'revision' => 'int', + 'active_job_id' => 'int', + 'created_at' => 'int', + 'updated_at' => 'int', + ]; +} diff --git a/web/app/Models/CloudRescueTemplateArtifact.php b/web/app/Models/CloudRescueTemplateArtifact.php new file mode 100644 index 00000000..e4ad3e66 --- /dev/null +++ b/web/app/Models/CloudRescueTemplateArtifact.php @@ -0,0 +1,27 @@ + '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', + ]; +} diff --git a/web/app/Models/CloudRescueTemplateReplica.php b/web/app/Models/CloudRescueTemplateReplica.php new file mode 100644 index 00000000..c58ac058 --- /dev/null +++ b/web/app/Models/CloudRescueTemplateReplica.php @@ -0,0 +1,25 @@ + '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', + ]; +} diff --git a/web/sql/cloud.sql b/web/sql/cloud.sql index ce8806b3..444da7b6 100644 --- a/web/sql/cloud.sql +++ b/web/sql/cloud.sql @@ -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 ( diff --git a/web/tests/CloudFreshSchemaContractTest.php b/web/tests/CloudFreshSchemaContractTest.php index c2fcd1c3..e287b642 100644 --- a/web/tests/CloudFreshSchemaContractTest.php +++ b/web/tests/CloudFreshSchemaContractTest.php @@ -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', diff --git a/web/tests/CloudRescueCatalogSchemaContractTest.php b/web/tests/CloudRescueCatalogSchemaContractTest.php new file mode 100644 index 00000000..4f3b2eb7 --- /dev/null +++ b/web/tests/CloudRescueCatalogSchemaContractTest.php @@ -0,0 +1,64 @@ + 'cloud_vpc_enabled'") && str_contains($setup, "'value' => 'false'") && str_contains($setup,