25 lines
789 B
PHP
25 lines
789 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = file_get_contents(__DIR__ . '/schema.sql');
|
|
$pdo->exec($sql);
|
|
echo "Database schema updated successfully.\n";
|
|
|
|
// Seed admin user
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM users WHERE email = 'admin@example.com'");
|
|
$user_exists = $stmt->fetchColumn();
|
|
|
|
if (!$user_exists) {
|
|
$password_hash = password_hash('password', PASSWORD_DEFAULT);
|
|
$stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute(['Admin User', 'admin@example.com', $password_hash, 'admin']);
|
|
echo "Admin user seeded successfully.\n";
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database migration failed: " . $e->getMessage() . "\n");
|
|
}
|
|
|