29 lines
864 B
PHP
29 lines
864 B
PHP
<?php
|
|
// db/migrate.php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
function run_migrations() {
|
|
try {
|
|
$pdo = db();
|
|
$migration_file = __DIR__ . '/migrations/001_create_murid_table.sql';
|
|
|
|
if (!file_exists($migration_file)) {
|
|
return ['success' => false, 'message' => 'File migrasi tidak ditemukan.'];
|
|
}
|
|
|
|
$sql = file_get_contents($migration_file);
|
|
$pdo->exec($sql);
|
|
|
|
return ['success' => true, 'message' => 'Migrasi tabel `murid` berhasil dijalankan.'];
|
|
} catch (PDOException $e) {
|
|
return ['success' => false, 'message' => 'Migrasi gagal: ' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
// Jalankan migrasi jika file ini dieksekusi langsung dari CLI atau via include
|
|
if (basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) {
|
|
$result = run_migrations();
|
|
echo $result['message'] . "\n";
|
|
}
|
|
|