<?php
$mysqli = new mysqli("127.0.0.1", "root", "", "siakad");

$sql1 = "CREATE TABLE `kelas_perkuliahan` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_kelas_kuliah_pddikti` varchar(36) DEFAULT NULL,
  `id_program_studi` int(11) unsigned DEFAULT NULL,
  `id_semester` varchar(10) DEFAULT NULL,
  `id_mata_kuliah` int(11) unsigned DEFAULT NULL,
  `nama_mata_kuliah` varchar(255) DEFAULT NULL,
  `nama_kelas_kuliah` varchar(50) DEFAULT NULL,
  `sks` int(11) DEFAULT 0,
  `jumlah_mahasiswa` int(11) DEFAULT 0,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_kelas_pddikti` (`id_kelas_kuliah_pddikti`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";

$sql2 = "CREATE TABLE `dosen_pengajar_kelas` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `id_aktivitas_mengajar_pddikti` varchar(36) DEFAULT NULL,
  `id_kelas_kuliah` varchar(36) DEFAULT NULL,
  `id_dosen` int(11) unsigned DEFAULT NULL,
  `nama_dosen` varchar(255) DEFAULT NULL,
  `sks_substansi_total` float DEFAULT 0,
  `rencana_tatap_muka` int(11) DEFAULT 0,
  `realisasi_tatap_muka` int(11) DEFAULT 0,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_kelas_dosen` (`id_kelas_kuliah`, `id_dosen`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";

$mysqli->query("DROP TABLE IF EXISTS dosen_pengajar_kelas");
$mysqli->query("DROP TABLE IF EXISTS kelas_perkuliahan");

if($mysqli->query($sql1)) {
    echo "kelas_perkuliahan ok\n";
} else echo $mysqli->error;

if($mysqli->query($sql2)) {
    echo "dosen_pengajar_kelas ok\n";
} else echo $mysqli->error;

// Update migrations table manually to fake the CI migration
$mysqli->query("INSERT INTO migrations (version, class, `group`, namespace, time, batch) VALUES ('2026-06-24-043000', 'App\\\Database\\\Migrations\\\CreateKelasPerkuliahanTable', 'default', 'App', UNIX_TIMESTAMP(), 1)");
$mysqli->query("INSERT INTO migrations (version, class, `group`, namespace, time, batch) VALUES ('2026-06-24-043001', 'App\\\Database\\\Migrations\\\CreateDosenPengajarKelasTable', 'default', 'App', UNIX_TIMESTAMP(), 1)");

