34318-vm/db/migrate.php
Flatlogic Bot 64b701287d v1
2025-09-23 20:48:22 +00:00

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");
}