27 lines
799 B
PHP
27 lines
799 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Run migrations
|
|
$migrations = glob(__DIR__ . '/migrations/*.sql');
|
|
sort($migrations);
|
|
foreach ($migrations as $migration) {
|
|
$sql = file_get_contents($migration);
|
|
$pdo->exec($sql);
|
|
}
|
|
|
|
// Add a default admin user if one doesn't exist
|
|
$stmt = $pdo->query("SELECT * FROM users WHERE username = 'admin'");
|
|
if ($stmt->rowCount() == 0) {
|
|
$username = 'admin';
|
|
$password = password_hash('password', PASSWORD_DEFAULT);
|
|
$pdo->prepare("INSERT INTO users (username, password) VALUES (?, ?)")->execute([$username, $password]);
|
|
}
|
|
|
|
echo "Database setup and seeding successful.";
|
|
} catch (PDOException $e) {
|
|
die("Database setup failed: " . $e->getMessage());
|
|
}
|