origin/schema-migration-xlvask-autopilot (#348)
Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
This commit is contained in:
co-authored by
Jeppe Bundgaard
parent
23fc410d25
commit
622fe59f5c
@@ -106,6 +106,10 @@ if ($args[1] === 'run') {
|
|||||||
echo "[" . date('Y-m-d H:i:s') . "][CRON_WORKER] Starting cron worker\n";
|
echo "[" . date('Y-m-d H:i:s') . "][CRON_WORKER] Starting cron worker\n";
|
||||||
(new \classes\cron_worker())->run();
|
(new \classes\cron_worker())->run();
|
||||||
break;
|
break;
|
||||||
|
case 'xlvask-automation-migrate':
|
||||||
|
echo "[" . date('Y-m-d H:i:s') . "][XLVASK] Ensuring automation schema readiness\n";
|
||||||
|
require_once 'cron/EnsureXLVaskAutomationSchema.php';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
echo "Invalid script name";
|
echo "Invalid script name";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use classes\xlvask_usage_logs_schema_bootstrap;
|
||||||
|
use xlvask\migrations\migration_20260804_xlvask_ai_auto_policy_v2;
|
||||||
|
|
||||||
|
require_once WD . '/classes/xlvask_usage_logs_schema_bootstrap.php';
|
||||||
|
require_once WD . '/classes/xlvask_autopilot_service.php';
|
||||||
|
require_once WD . '/modules/xlvask/migrations/20260804_xlvask_ai_auto_policy_v2.php';
|
||||||
|
|
||||||
|
if (!defined('WD')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbTarget = strtolower(trim((string)(getenv('CONFIG_DB_TARGET') ?: 'live')));
|
||||||
|
$startedAt = date('Y-m-d H:i:s');
|
||||||
|
echo "[{$startedAt}][XLVASK] Target database: {$dbTarget}" . PHP_EOL;
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'success' => false,
|
||||||
|
'db_target' => $dbTarget,
|
||||||
|
'preflight' => null,
|
||||||
|
'applied' => false,
|
||||||
|
'postflight' => null,
|
||||||
|
'wash_id_uniqueness_ready' => false,
|
||||||
|
'wash_id_uniqueness_activated' => false,
|
||||||
|
'wash_id_uniqueness_blocked' => false,
|
||||||
|
'error' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$preflight = migration_20260804_xlvask_ai_auto_policy_v2::preflight();
|
||||||
|
$result['preflight'] = $preflight;
|
||||||
|
|
||||||
|
if (!(bool)($preflight['ready'] ?? false)) {
|
||||||
|
$result['postflight'] = migration_20260804_xlvask_ai_auto_policy_v2::apply();
|
||||||
|
$result['applied'] = true;
|
||||||
|
} else {
|
||||||
|
$result['postflight'] = $preflight;
|
||||||
|
}
|
||||||
|
|
||||||
|
$postflight = (array)$result['postflight'];
|
||||||
|
if (!(bool)($postflight['ready'] ?? false)) {
|
||||||
|
throw new RuntimeException('XL Vask automation schema is still not ready after apply.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xlvask_usage_logs_schema_bootstrap::washIdUniquenessReady()) {
|
||||||
|
$result['wash_id_uniqueness_ready'] = true;
|
||||||
|
} else {
|
||||||
|
$activated = xlvask_usage_logs_schema_bootstrap::applyWashIdUniquenessMigration();
|
||||||
|
$result['wash_id_uniqueness_ready'] = $activated && xlvask_usage_logs_schema_bootstrap::washIdUniquenessReady();
|
||||||
|
$result['wash_id_uniqueness_activated'] = $result['wash_id_uniqueness_ready'];
|
||||||
|
$result['wash_id_uniqueness_blocked'] = !$result['wash_id_uniqueness_ready'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result['success'] = (bool)$result['wash_id_uniqueness_ready'];
|
||||||
|
if (!$result['success']) {
|
||||||
|
$result['error'] = 'Wash-id uniqueness is blocked, likely due duplicate normalized wash_id values.';
|
||||||
|
}
|
||||||
|
} catch (Throwable $throwable) {
|
||||||
|
$result['error'] = $throwable->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL;
|
||||||
|
|
||||||
|
if (!$result['success']) {
|
||||||
|
throw new RuntimeException((string)($result['error'] ?: 'XL Vask schema readiness failed.'));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ require_once __DIR__ . '/classes/cors_policy.php';
|
|||||||
|
|
||||||
/** CORS */
|
/** CORS */
|
||||||
// OPTIONS requests are preflight requests for CORS, we can just return a 200 OK response
|
// OPTIONS requests are preflight requests for CORS, we can just return a 200 OK response
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'OPTIONS') {
|
||||||
$preflight = \classes\cors_policy::preflightResponse($_SERVER['HTTP_ORIGIN'] ?? '', (string)($CORS ?? ''));
|
$preflight = \classes\cors_policy::preflightResponse($_SERVER['HTTP_ORIGIN'] ?? '', (string)($CORS ?? ''));
|
||||||
\classes\cors_policy::emitHeaders($preflight['headers']);
|
\classes\cors_policy::emitHeaders($preflight['headers']);
|
||||||
http_response_code($preflight['status']);
|
http_response_code($preflight['status']);
|
||||||
|
|||||||
Reference in New Issue
Block a user