35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
error_log("Database connection successful.");
|
|
|
|
// Run initial schema
|
|
$sql_schema = file_get_contents(__DIR__ . '/migrations/001_initial_schema.sql');
|
|
if ($sql_schema === false) {
|
|
throw new Exception("Could not read schema file.");
|
|
}
|
|
$pdo->exec($sql_schema);
|
|
error_log("Schema migration applied successfully.");
|
|
|
|
// Run seed data
|
|
$sql_seed = file_get_contents(__DIR__ . '/migrations/002_seed_data.sql');
|
|
if ($sql_seed === false) {
|
|
throw new Exception("Could not read seed file.");
|
|
}
|
|
$pdo->exec($sql_seed);
|
|
error_log("Data seeding applied successfully.");
|
|
|
|
echo "Database setup complete!";
|
|
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
error_log("Database error: " . $e->getMessage());
|
|
die("Database error: " . $e->getMessage());
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
error_log("Error: " . $e->getMessage());
|
|
die("Error: " . $e->getMessage());
|
|
}
|