diff --git a/fixdata.php b/fixdata.php index f016667..21286c3 100644 --- a/fixdata.php +++ b/fixdata.php @@ -3,29 +3,101 @@ require_once 'koneksi.php'; echo "
Kolom $column sudah ada, dilewati.
"; + return; + } + + $afterSql = ""; + + if ($afterColumn && columnExists($conn, $table, $afterColumn)) { + $afterSql = " AFTER `$afterColumn`"; + } + + $sql = "ALTER TABLE `$table` ADD COLUMN `$column` $definition $afterSql"; + + if ($conn->query($sql)) { + echo "Kolom $column berhasil ditambahkan.
"; } else { - if ($conn->query($sql)) { - echo "Kolom $column berhasil ditambahkan.
"; - } else { - echo "Gagal tambah kolom $column: " . htmlspecialchars($conn->error) . "
"; - } + echo "Gagal tambah kolom $column: " . htmlspecialchars($conn->error) . "
"; } } +$table = "bantuan_tersalur"; + +if (!tableExists($conn, $table)) { + die("Tabel bantuan_tersalur belum ada. Import database.sql dulu.
"); +} + +// Tambahkan kolom status dulu karena status_konfirmasi ingin diletakkan setelah status. +addColumnIfMissing( + $conn, + $table, + "status", + "ENUM('Pending','Tersalurkan') NOT NULL DEFAULT 'Tersalurkan'", + "created_at" +); + +addColumnIfMissing( + $conn, + $table, + "status_konfirmasi", + "ENUM('Menunggu','Dikonfirmasi','Ditolak') NOT NULL DEFAULT 'Menunggu'", + "status" +); + +addColumnIfMissing( + $conn, + $table, + "nama_penerima_konfirmasi", + "VARCHAR(150) DEFAULT NULL", + "status_konfirmasi" +); + +addColumnIfMissing( + $conn, + $table, + "catatan_konfirmasi", + "TEXT DEFAULT NULL", + "nama_penerima_konfirmasi" +); + +addColumnIfMissing( + $conn, + $table, + "dikonfirmasi_oleh", + "INT DEFAULT NULL", + "catatan_konfirmasi" +); + +addColumnIfMissing( + $conn, + $table, + "tgl_konfirmasi", + "TIMESTAMP NULL DEFAULT NULL", + "dikonfirmasi_oleh" +); + +$conn->query("UPDATE `$table` SET status = 'Tersalurkan' WHERE status IS NULL"); +$conn->query("UPDATE `$table` SET status_konfirmasi = 'Menunggu' WHERE status_konfirmasi IS NULL"); + echo "Selesai. Coba buka dashboard relawan lagi.
"; -echo "Setelah berhasil, hapus file fix_kolom_bantuan.php dari repo.
Selesai. Coba buka dashboard relawan lagi.
"; +echo "Setelah berhasil, hapus file fixdata.php dari repo lalu redeploy.