60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function seed_database() {
|
|
$pdo = db();
|
|
|
|
// Seed admin user
|
|
$email = 'admin@flexpass.local';
|
|
$password = 'password';
|
|
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
try {
|
|
// Check if user already exists
|
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
|
$stmt->execute([$email]);
|
|
if ($stmt->fetch()) {
|
|
echo "Admin user already exists.\n";
|
|
} else {
|
|
$stmt = $pdo->prepare("INSERT INTO users (email, password_enc, role, display_name) VALUES (?, ?, 'Admin', 'Admin User')");
|
|
$stmt->execute([$email, $hashedPassword]);
|
|
echo "Admin user created successfully.\n";
|
|
echo "Email: " . $email . "\n";
|
|
echo "Password: " . $password . "\n";
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo "Error seeding database: " . $e->getMessage() . "\n";
|
|
return false;
|
|
}
|
|
|
|
// Seed clients
|
|
try {
|
|
$stmt = $pdo->query("SELECT count(*) FROM clients");
|
|
if ($stmt->fetchColumn() > 0) {
|
|
echo "Clients table already seeded.\n";
|
|
} else {
|
|
$clients = [
|
|
['1001', 'Stark Industries', 'active'],
|
|
['1002', 'Wayne Enterprises', 'active'],
|
|
['1003', 'Cyberdyne Systems', 'inactive'],
|
|
];
|
|
$stmt = $pdo->prepare("INSERT INTO clients (client_id, name, status) VALUES (?, ?, ?)");
|
|
foreach ($clients as $client) {
|
|
$stmt->execute($client);
|
|
}
|
|
echo "Seeded " . count($clients) . " clients.\n";
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo "Error seeding clients: " . $e->getMessage() . "\n";
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
if (php_sapi_name() === 'cli') {
|
|
seed_database();
|
|
}
|
|
?>
|