Files
Recruitment-HC/docker/migrate.php
T
NikoKS 045d3a8fd3
Build and publish Docker image / build (push) Failing after 41s
added migration
2026-10-15 00:05:11 +07:00

39 lines
1.6 KiB
PHP

<?php
if (PHP_SAPI !== 'cli') {
http_response_code(404);
exit;
}
try {
require '/var/www/html/includes/conn.php';
foreach (['in_daper', 'in_soal', 'in_jawab'] as $table) {
$conn->query("SELECT 1 FROM `$table` LIMIT 0");
}
foreach (['001_admin.sql', '002_admin_identity.sql', '003_exam_attempts.sql'] as $file) {
// Only migrate the historical rec_admin schema, preserving identities.
if ($file === '002_admin_identity.sql'
&& $conn->query("SHOW COLUMNS FROM rec_admin LIKE 'name'")->num_rows === 0) {
continue;
}
$sql = file_get_contents('/var/www/html/dashboard/migrations/' . $file);
$conn->multi_query($sql);
do {
$result = $conn->store_result();
if ($result instanceof mysqli_result) {
$result->free();
}
} while ($conn->more_results() && $conn->next_result());
fwrite(STDOUT, "Applied: $file\n");
}
// Fail the one-shot service before starting Apache if setup is incomplete.
foreach (['rec_admin', 'rec_exam_attempt', 'rec_exam_event', 'rec_candidate_login_guard'] as $table) {
$conn->query("SELECT 1 FROM `$table` LIMIT 0");
}
$conn->query('SELECT email, nama_de, nama_be, idkar, password_hash FROM rec_admin LIMIT 0');
fwrite(STDOUT, "Database ready. Existing accounts and test data were preserved.\n");
} catch (Throwable $error) {
fwrite(STDERR, 'Migration failed: ' . $error->getMessage() . "\nReview setup logs and docs/deployment.md before retrying.\n");
exit(1);
}