You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.4 KiB
PHP
80 lines
3.4 KiB
PHP
<?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',
|
|
'schedule_attempt INT UNSIGNED NOT NULL DEFAULT 0',
|
|
] 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.');
|
|
$assert(str_contains($backup,
|
|
'UNIQUE KEY cloud_instance_backup_schedule (')
|
|
&& str_contains($backup,
|
|
'subscription_id, scheduled_for, schedule_attempt')
|
|
&& str_contains($backup,
|
|
'CONSTRAINT chk_cloud_instance_backup_schedule_shape CHECK (')
|
|
&& str_contains($backup, 'schedule_attempt = 0')
|
|
&& str_contains($backup, 'schedule_attempt >= 1'),
|
|
'Automatic backup schedule attempts are not durably generation-fenced.');
|
|
|
|
foreach ([
|
|
'create_request_actor_id',
|
|
'create_request_idempotency_key',
|
|
'create_request_fingerprint',
|
|
'cloud_instance_backup_create_request',
|
|
'chk_cloud_instance_backup_create_request',
|
|
'schedule_attempt',
|
|
'chk_cloud_instance_backup_schedule_shape',
|
|
] as $required) {
|
|
$assert(str_contains($setup, "'" . $required . "'"),
|
|
'CloudSetup omits backup preparation contract: ' . $required);
|
|
}
|
|
$assert(str_contains($setup,
|
|
"SCHEMA_VERSION = 'go-agent-wss-v52-daily-traffic-settlement'")
|
|
&& 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, "'schedule_attempt' => '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";
|