47 lines
1.6 KiB
PHP
47 lines
1.6 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function run_migrations() {
|
|
$pdo = db();
|
|
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
|
sort($migration_files);
|
|
|
|
foreach ($migration_files as $file) {
|
|
echo "Running migration: " . basename($file) . "...\n";
|
|
$sql = file_get_contents($file);
|
|
try {
|
|
$pdo->exec($sql);
|
|
echo "Success.\n";
|
|
} catch (PDOException $e) {
|
|
die("Migration failed: " . $e->getMessage() . "\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
function seed_data() {
|
|
$pdo = db();
|
|
// Seed users only if the table is empty
|
|
$stmt = $pdo->query('SELECT COUNT(*) FROM users');
|
|
if ($stmt->fetchColumn() == 0) {
|
|
echo "Seeding users...\n";
|
|
$users = [
|
|
['username' => 'admin', 'email' => 'admin@nic.app', 'password_hash' => password_hash('password', PASSWORD_DEFAULT), 'kyc_status' => 'approved'],
|
|
['username' => 'alice', 'email' => 'alice@nic.app', 'password_hash' => password_hash('password', PASSWORD_DEFAULT), 'kyc_status' => 'pending'],
|
|
['username' => 'bob', 'email' => 'bob@nic.app', 'password_hash' => password_hash('password', PASSWORD_DEFAULT), 'kyc_status' => 'rejected'],
|
|
];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO users (username, email, password_hash, kyc_status) VALUES (:username, :email, :password_hash, :kyc_status)");
|
|
|
|
foreach ($users as $user) {
|
|
$stmt->execute($user);
|
|
}
|
|
echo "Seeding complete.\n";
|
|
} else {
|
|
echo "Users table is not empty, skipping seed.\n";
|
|
}
|
|
}
|
|
|
|
run_migrations();
|
|
seed_data();
|
|
|