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.
65 lines
3.1 KiB
PHP
65 lines
3.1 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$schema = file_get_contents($root . '/sql/cloud.sql');
|
|
$baseSchema = file_get_contents($root . '/sql/ss.sql');
|
|
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
|
|
if (!is_string($schema) || !is_string($baseSchema) || !is_string($setup)) {
|
|
throw new RuntimeException('Fresh schema files are unreadable.');
|
|
}
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$assert(preg_match('/\b(?:ALTER|DROP)\s+TABLE\b/i', $schema) !== 1,
|
|
'cloud.sql must contain only fresh-install DDL.');
|
|
$assert(stripos($schema, 'compatibility import') === false
|
|
&& stripos($schema, 'upgrade an existing') === false,
|
|
'cloud.sql retained an old-database migration path.');
|
|
$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-v1'")
|
|
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
|
|
'Outbound Agent schema must reject the incompatible earlier Go database.');
|
|
|
|
foreach (['cloud_host_agents', 'cloud_templates', 'cloud_hosts', 'cloud_instances',
|
|
'cloud_orders', 'cloud_invoices', 'cloud_jobs', 'cloud_console_tickets',
|
|
'cloud_rescue_template_imports'] as $table) {
|
|
$assert(str_contains($schema, 'CREATE TABLE IF NOT EXISTS ' . $table . ' ('),
|
|
'Missing fresh-install table: ' . $table);
|
|
}
|
|
$assert(str_contains($schema,
|
|
'operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY')
|
|
&& str_contains($schema,
|
|
'UNIQUE KEY cloud_rescue_import_template (host_id, template_id)')
|
|
&& str_contains($schema,
|
|
'import_type VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL'),
|
|
'Fresh schema is missing the durable rescue-template import identity.');
|
|
$assert(str_contains($schema, 'sealed_api_secret LONGTEXT NOT NULL')
|
|
&& str_contains($schema,
|
|
'tested_revision BIGINT UNSIGNED NOT NULL DEFAULT 0')
|
|
&& str_contains($schema, 'sealed_payload LONGTEXT')
|
|
&& str_contains($schema, 'sealed_credential LONGTEXT')
|
|
&& str_contains($schema, 'sealed_agent_ticket LONGTEXT NOT NULL'),
|
|
'Fresh schema is missing purpose-bound sealed data columns.');
|
|
$assert(!str_contains($schema, 'agent_websocket_url')
|
|
&& !str_contains($schema, 'endpoint VARCHAR(255)'),
|
|
'Fresh schema retained a panel-to-host Agent endpoint.');
|
|
$assert(!str_contains($schema, 'api_secret_cipher')
|
|
&& !str_contains($schema, 'payload_cipher')
|
|
&& !str_contains($schema, 'credential_cipher'),
|
|
'Fresh schema retained retired ciphertext column names.');
|
|
foreach (['cloud_order_admin_created', 'cloud_invoice_admin_created',
|
|
'cloud_invoice_payment_admin_created'] as $index) {
|
|
$assert(str_contains($schema, 'KEY ' . $index . ' ('),
|
|
'Fresh schema did not inline index: ' . $index);
|
|
}
|
|
$assert(str_contains($baseSchema,
|
|
'ADD KEY `ticket_instance` (`instance_id`,`userid`,`rootid`)'),
|
|
'Fresh ticket schema is missing the instance ownership index.');
|
|
|
|
echo "Clean-break fresh cloud schema contract passed.\n";
|