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.
83 lines
3.4 KiB
PHP
83 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');
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
foreach ([
|
|
'cloud_service_compensations',
|
|
'cloud_service_compensation_items',
|
|
'cloud_service_compensation_recipients',
|
|
] as $table) {
|
|
$assert(str_contains($schema, 'CREATE TABLE ' . $table . ' ('),
|
|
'Service compensation schema is missing ' . $table . '.');
|
|
$assert(str_contains($setup, "'" . $table . "'"),
|
|
'CloudSetup does not require ' . $table . '.');
|
|
}
|
|
|
|
foreach ([
|
|
'UNIQUE KEY cloud_service_compensation_request',
|
|
'UNIQUE KEY cloud_service_compensation_incident_identity (id, incident_key)',
|
|
'UNIQUE KEY cloud_service_compensation_item_incident (incident_key, instance_id)',
|
|
'UNIQUE KEY cloud_service_compensation_recipient (batch_id, user_id)',
|
|
'KEY cloud_service_compensation_item_due (state, available_at, id)',
|
|
'KEY cloud_service_compensation_item_lease (state, lease_until, id)',
|
|
'KEY cloud_service_compensation_recipient_due (status, available_at, id)',
|
|
'KEY cloud_service_compensation_recipient_lease (status, lease_until, id)',
|
|
'fk_cloud_service_compensation_item_batch',
|
|
'FOREIGN KEY (batch_id, incident_key)',
|
|
'fk_cloud_service_compensation_recipient_batch',
|
|
"scope_type IN ('instance','host','public_ip_pool')",
|
|
'compensation_seconds BETWEEN 1 AND 31622400',
|
|
] as $contract) {
|
|
$assert(str_contains($schema, $contract),
|
|
'Service compensation schema lost contract: ' . $contract);
|
|
}
|
|
|
|
foreach ([
|
|
'chk_cloud_service_compensation_scope',
|
|
'chk_cloud_service_compensation_request',
|
|
'chk_cloud_service_compensation_window',
|
|
'chk_cloud_service_compensation_counts',
|
|
'chk_cloud_service_compensation_state',
|
|
'chk_cloud_service_compensation_terminal',
|
|
'chk_cloud_service_compensation_item_state',
|
|
'chk_cloud_service_compensation_item_window',
|
|
'chk_cloud_service_compensation_item_lease',
|
|
'chk_cloud_service_compensation_item_terminal',
|
|
'chk_cloud_service_compensation_item_applied',
|
|
'chk_cloud_service_compensation_item_error',
|
|
'chk_cloud_service_compensation_recipient_status',
|
|
'chk_cloud_service_compensation_recipient_payload',
|
|
'chk_cloud_service_compensation_recipient_shape',
|
|
] as $check) {
|
|
$assert(str_contains($setup, "'" . $check . "'"),
|
|
'CloudSetup lost service compensation check: ' . $check);
|
|
}
|
|
|
|
foreach ([
|
|
"'columns' => ['id', 'incident_key']",
|
|
"'columns' => ['incident_key', 'instance_id']",
|
|
"'columns' => ['state', 'available_at', 'id']",
|
|
"'columns' => ['state', 'lease_until', 'id']",
|
|
"'columns' => ['batch_id', 'user_id']",
|
|
"'columns' => ['status', 'available_at', 'id']",
|
|
"'columns' => ['status', 'lease_until', 'id']",
|
|
"'fk_cloud_service_compensation_item_batch'",
|
|
"'fk_cloud_service_compensation_recipient_batch'",
|
|
] as $setupContract) {
|
|
$assert(str_contains($setup, $setupContract),
|
|
'CloudSetup lost service compensation contract: ' . $setupContract);
|
|
}
|
|
|
|
$assert(str_contains($setup,
|
|
"SCHEMA_VERSION = 'go-agent-wss-v35-service-compensations'"),
|
|
'CloudSetup schema version was not advanced for service compensation.');
|
|
|
|
echo "Service compensation schema contracts passed.\n";
|