-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.php
33 lines (30 loc) · 1.03 KB
/
migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require_once __DIR__ . '/config.php';
try {
// Run migrations
$migration_files = glob(__DIR__ . '/database/migration/*.php');
foreach ($migration_files as $file) {
require_once $file;
$functionName = 'up_' . basename($file, '.php');
if (function_exists($functionName)) {
call_user_func($functionName, $pdo); // Call the up function
}
}
// Run seeders
$seeder_files = glob(__DIR__ . '/database/seeder/*.php');
foreach ($seeder_files as $file) {
require_once $file;
$functionName = basename($file, '.php'); // Correct usage
if (function_exists($functionName)) {
call_user_func($functionName, $pdo);
} else {
echo "Function $functionName does not exist.\n"; // Debugging line
}
}
echo "Migration and seeding completed successfully.\n";
} catch (PDOException $e) {
echo "Database error: " . $e->getMessage() . "\n";
} catch (Exception $e) {
echo "General error: " . $e->getMessage() . "\n";
}
?>