feat(storage): persist backup preparation identity

go
codex 2 weeks ago
parent f8c35863ba
commit 77d16f080d

@ -8,7 +8,7 @@ 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-v37-storage-publications';
private const SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation';
private const MAIN_TABLES = [
'cloud_regions', 'cloud_traffic_pool_groups',
'cloud_network_lines', 'cloud_resource_pools',
@ -312,7 +312,9 @@ final class CloudSetup
'source', 'paid_at', 'created_at', 'updated_at',
],
'cloud_instance_backups' => [
'id', 'backup_key', 'storage_artifact_id',
'id', 'backup_key', 'create_request_actor_id',
'create_request_idempotency_key',
'create_request_fingerprint', 'storage_artifact_id',
'source_instance_id', 'source_host_id',
'user_id', 'source_uuid', 'name', 'purpose', 'source',
'subscription_id', 'scheduled_for', 'state', 'consistency',
@ -605,6 +607,9 @@ final class CloudSetup
'chk_cloud_storage_operation_effect',
'chk_cloud_storage_operation_terminal',
],
'cloud_instance_backups' => [
'chk_cloud_instance_backup_create_request',
],
'cloud_public_ip_pool_catalog_mutex' => [
'chk_cloud_public_ip_pool_catalog_mutex',
],
@ -1067,6 +1072,7 @@ final class CloudSetup
],
'cloud_instance_backups' => [
'PRIMARY', 'cloud_instance_backup_key',
'cloud_instance_backup_create_request',
'cloud_instance_backup_storage',
'cloud_instance_backup_object', 'cloud_instance_backup_schedule',
'cloud_instance_backup_source',
@ -1169,6 +1175,15 @@ final class CloudSetup
* non-unique. Column order is part of the ownership/fencing semantics.
*/
private const REQUIRED_INDEX_SHAPES = [
'cloud_instance_backups' => [
'cloud_instance_backup_create_request' => [
'non_unique' => 0,
'columns' => [
'create_request_actor_id',
'create_request_idempotency_key',
],
],
],
'cloud_maintenance_notices' => [
'cloud_maintenance_notice_key' => [
'non_unique' => 0,

@ -12,9 +12,13 @@ final class CloudInstanceBackup extends Model
protected $hidden = [
'sealed_storage_runtime', 'sealed_credential', 'object_etag',
'object_version_id', 'delete_operation_id',
'create_request_actor_id', 'create_request_idempotency_key',
'create_request_fingerprint',
];
protected $casts = [
'id' => 'int',
'create_request_actor_id' => 'int',
'storage_artifact_id' => 'int',
'source_instance_id' => 'int',
'source_host_id' => 'int',
'user_id' => 'int',

@ -1398,6 +1398,9 @@ CREATE TABLE cloud_backup_period_entitlements (
CREATE TABLE cloud_instance_backups (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
backup_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
create_request_actor_id BIGINT UNSIGNED DEFAULT NULL,
create_request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
create_request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
storage_artifact_id BIGINT UNSIGNED DEFAULT NULL,
source_instance_id BIGINT UNSIGNED NOT NULL,
source_host_id BIGINT UNSIGNED NOT NULL,
@ -1437,6 +1440,7 @@ CREATE TABLE cloud_instance_backups (
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_instance_backup_key (backup_key),
UNIQUE KEY cloud_instance_backup_create_request (create_request_actor_id, create_request_idempotency_key),
UNIQUE KEY cloud_instance_backup_storage (storage_artifact_id),
UNIQUE KEY cloud_instance_backup_object (object_key),
UNIQUE KEY cloud_instance_backup_schedule (subscription_id, scheduled_for),
@ -1444,6 +1448,15 @@ CREATE TABLE cloud_instance_backups (
KEY cloud_instance_backup_owner (user_id, id),
KEY cloud_instance_backup_operation (last_operation_id),
KEY cloud_instance_backup_delete_due (state, delete_next_check_at, id),
CONSTRAINT chk_cloud_instance_backup_create_request CHECK (
(create_request_actor_id IS NULL
AND create_request_idempotency_key IS NULL
AND create_request_fingerprint IS NULL)
OR (create_request_actor_id IS NOT NULL
AND create_request_idempotency_key IS NOT NULL
AND CHAR_LENGTH(create_request_idempotency_key) BETWEEN 16 AND 128
AND create_request_fingerprint REGEXP '^[a-f0-9]{64}$')
),
CONSTRAINT fk_cloud_instance_backup_storage FOREIGN KEY (storage_artifact_id)
REFERENCES cloud_storage_artifacts (id)
ON DELETE RESTRICT ON UPDATE RESTRICT

@ -0,0 +1,66 @@
<?php
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
$model = file_get_contents(
$root . '/app/Models/CloudInstanceBackup.php'
);
if (!is_string($schema) || !is_string($setup) || !is_string($model)) {
throw new RuntimeException('Backup preparation schema sources are unreadable.');
}
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$matched = preg_match(
'/CREATE TABLE cloud_instance_backups \(([\s\S]*?)\n\) ENGINE=InnoDB/',
$schema,
$match
) === 1;
$assert($matched, 'Missing cloud_instance_backups table.');
$backup = $match[1];
foreach ([
'create_request_actor_id BIGINT UNSIGNED DEFAULT NULL',
'create_request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL',
'create_request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL',
] as $column) {
$assert(str_contains($backup, $column),
'Missing durable backup request field: ' . $column);
}
$assert(str_contains($backup,
'UNIQUE KEY cloud_instance_backup_create_request (create_request_actor_id, create_request_idempotency_key)')
&& str_contains($backup,
'CONSTRAINT chk_cloud_instance_backup_create_request CHECK (')
&& str_contains($backup, 'create_request_actor_id IS NULL')
&& str_contains($backup, 'create_request_actor_id IS NOT NULL')
&& str_contains($backup,
"create_request_fingerprint REGEXP '^[a-f0-9]{64}$'"),
'Backup request identity is not atomically shaped or uniquely fenced.');
foreach ([
'create_request_actor_id',
'create_request_idempotency_key',
'create_request_fingerprint',
'cloud_instance_backup_create_request',
'chk_cloud_instance_backup_create_request',
] as $required) {
$assert(str_contains($setup, "'" . $required . "'"),
'CloudSetup omits backup preparation contract: ' . $required);
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup,
"'columns' => [\n 'create_request_actor_id',\n 'create_request_idempotency_key',")
&& str_contains($setup, "'non_unique' => 0"),
'CloudSetup does not verify the exact unique request fence.');
$assert(str_contains($model, "'create_request_actor_id' => 'int'")
&& str_contains($model, "'storage_artifact_id' => 'int'")
&& str_contains($model, "'create_request_idempotency_key'")
&& str_contains($model, "'create_request_fingerprint'"),
'Backup model exposes or miscasts durable preparation identity.');
echo "Backup publication preparation schema contracts passed.\n";

@ -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-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'Outbound Agent schema must reject the incompatible earlier Go database.');
$assert(str_contains($schema,

@ -56,7 +56,7 @@ foreach ([
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'"),
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'"),
'CloudSetup schema version was not advanced for maintenance notices.');
echo "Maintenance notice schema contracts passed.\n";

@ -53,7 +53,7 @@ $assert(is_string($schema)
'Public-pool replacement lacks durable batch, child, or claim schema.');
$assert(is_string($setup)
&& str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup,
"'cloud_public_ip_pool_replacement_batches'")
&& str_contains($setup,

@ -170,7 +170,7 @@ $assert(str_contains($setup,
'CloudSetup does not verify index uniqueness and ordered columns.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup, "'cloud_public_network_transitions'")
&& str_contains($setup, "'cloud_public_network_transition_ips'")
&& str_contains($setup, "'reservation_ip_claim_id'")

@ -56,7 +56,7 @@ $assert($replica !== ''
&& 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-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup, "'cloud_rescue_artifact_delete_due'")
&& str_contains($setup, "'cloud_rescue_replica_cleanup'"),
'CloudSetup version or rescue catalog indexes are incomplete.');

@ -218,7 +218,7 @@ foreach ([
'CloudSetup omits restore/migration ledger contract: ' . $required);
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($attemptModel,
"protected \$table = 'cloud_backup_restore_attempts';")
&& str_contains($attemptModel, "'active_attempt' => 'int'")

@ -105,7 +105,7 @@ $assert(str_contains($setup,
'CloudSetup lost the open-compensation fence index contract.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'"),
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'"),
'CloudSetup schema version was not advanced for service compensation.');
$appliedShape = preg_match(

@ -137,7 +137,7 @@ $assert(is_string($publicationModel)
&& str_contains($artifactModel, "'maximum_size_bytes' => 'int'"),
'Storage publication/artifact model contracts are incomplete.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'"),
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'"),
'CloudSetup schema version was not advanced for durable publications.');
echo "Storage publication schema contracts passed.\n";

@ -63,7 +63,7 @@ $assert(str_contains($schema,
&& str_contains($schema,
'CONSTRAINT chk_cloud_template_import_completion CHECK (')
&& str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'"),
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'"),
'Template imports are missing durable identity or terminal-state constraints.');
$assert(str_contains($routes, "'/admin/cloud-template-imports'")
&& str_contains($routes, "'/admin/cloud-template-imports/{id}'")

@ -71,7 +71,7 @@ $assert(str_contains($schema,
'Service-period traffic-pool identity is not frozen or indexed.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v37-storage-publications'")
"SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup, "'chk_cloud_traffic_entitlement_balance'")
&& str_contains($setup, "'cloud_traffic_ledger_sequence'"),
'CloudSetup schema version or named-object validation is incomplete.');

@ -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-v37-storage-publications'")
"private const SCHEMA_VERSION = 'go-agent-wss-v38-backup-publication-preparation'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup,

Loading…
Cancel
Save