29 lines
831 B
PHP
29 lines
831 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function run_migrations() {
|
|
try {
|
|
$pdo = db();
|
|
$sql_file = __DIR__ . '/migrations/001_create_jobs_table.sql';
|
|
|
|
if (!file_exists($sql_file)) {
|
|
return ['success' => false, 'error' => 'Migration file not found.'];
|
|
}
|
|
|
|
$sql = file_get_contents($sql_file);
|
|
$pdo->exec($sql);
|
|
|
|
return ['success' => true, 'message' => 'Database setup and seeding completed successfully.'];
|
|
} catch (PDOException $e) {
|
|
return ['success' => false, 'error' => 'Database error: ' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
// If this script is run directly from the command line, execute the migrations.
|
|
if (php_sapi_name() === 'cli') {
|
|
$result = run_migrations();
|
|
echo $result['message'] ?? $result['error'];
|
|
echo "\n";
|
|
}
|
|
|