feat(storage): persist backup preparation identity
parent
f8c35863ba
commit
77d16f080d
@ -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";
|
||||
Loading…
Reference in New Issue