diff --git a/database/migrations/2026_02_14_235500_fix_peminjaman_fk.php b/database/migrations/2026_02_14_235500_fix_peminjaman_fk.php index 09fde3e..202cfb8 100644 --- a/database/migrations/2026_02_14_235500_fix_peminjaman_fk.php +++ b/database/migrations/2026_02_14_235500_fix_peminjaman_fk.php @@ -13,30 +13,52 @@ public function up(): void { // 1. Hapus semua kemungkinan Foreign Key lama agar tidak bentrok - try { DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY peminjaman_ibfk_1'); } catch (\Exception $e) {} - try { DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY peminjaman_ibfk_2'); } catch (\Exception $e) {} - try { DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY fk_peminjaman_user'); } catch (\Exception $e) {} - try { DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY fk_peminjaman_buku'); } catch (\Exception $e) {} - + try { + DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY peminjaman_ibfk_1'); + } catch (\Exception $e) { + } + try { + DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY peminjaman_ibfk_2'); + } catch (\Exception $e) { + } + try { + DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY fk_peminjaman_user'); + } catch (\Exception $e) { + } + try { + DB::statement('ALTER TABLE peminjaman DROP FOREIGN KEY fk_peminjaman_buku'); + } catch (\Exception $e) { + } + // Menghapus default foreign key dari Laravel - try { Schema::table('peminjaman', function (Blueprint $table) { $table->dropForeign(['id_user']); }); } catch (\Exception $e) {} - try { Schema::table('peminjaman', function (Blueprint $table) { $table->dropForeign(['id_buku']); }); } catch (\Exception $e) {} + try { + Schema::table('peminjaman', function (Blueprint $table) { + $table->dropForeign(['id_user']); + }); + } catch (\Exception $e) { + } + try { + Schema::table('peminjaman', function (Blueprint $table) { + $table->dropForeign(['id_buku']); + }); + } catch (\Exception $e) { + } // 2. Samakan Tipe Data (Ditaruh di LUAR Schema::table agar pasti dieksekusi duluan) - DB::statement('ALTER TABLE peminjaman MODIFY id_user BIGINT UNSIGNED NOT NULL'); - DB::statement('ALTER TABLE peminjaman MODIFY id_buku INT NOT NULL'); + DB::statement('ALTER TABLE peminjaman MODIFY id_user BIGINT UNSIGNED NOT NULL'); + DB::statement('ALTER TABLE peminjaman MODIFY id_buku BIGINT UNSIGNED NOT NULL'); // 3. Buat Relasi Baru yang Benar Schema::table('peminjaman', function (Blueprint $table) { $table->foreign('id_user') - ->references('id') - ->on('users') - ->onDelete('cascade'); - + ->references('id') + ->on('users') + ->onDelete('cascade'); + $table->foreign('id_buku') - ->references('id_buku') - ->on('buku') - ->onDelete('cascade'); + ->references('id') + ->on('bukus') + ->onDelete('cascade'); }); } @@ -48,7 +70,7 @@ public function down(): void Schema::table('peminjaman', function (Blueprint $table) { // Hapus kedua relasi jika migration di-rollback $table->dropForeign(['id_user']); - $table->dropForeign(['id_buku']); + $table->dropForeign(['id_buku']); }); } -}; \ No newline at end of file +}; diff --git a/database/migrations/2026_02_14_235600_create_buku_tamu_table.php b/database/migrations/2026_02_14_235600_create_buku_tamu_table.php new file mode 100644 index 0000000..fbeb527 --- /dev/null +++ b/database/migrations/2026_02_14_235600_create_buku_tamu_table.php @@ -0,0 +1,40 @@ +id(); + $table->unsignedBigInteger('id_user')->nullable(); + $table->string('nama_tamu'); + $table->string('email')->nullable(); + $table->string('no_hp')->nullable(); + $table->string('asal_instansi')->nullable(); + $table->string('status')->nullable(); + $table->text('tujuan_kunjungan')->nullable(); + $table->date('tanggal_kunjungan')->nullable(); + $table->timestamps(); + + $table->foreign('id_user') + ->references('id') + ->on('users') + ->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('buku_tamu'); + } +}; diff --git a/database/migrations/2026_02_15_000000_fix_buku_tamu_fk.php b/database/migrations/2026_02_15_000000_fix_buku_tamu_fk.php index 4d6e5dd..a07d121 100644 --- a/database/migrations/2026_02_15_000000_fix_buku_tamu_fk.php +++ b/database/migrations/2026_02_15_000000_fix_buku_tamu_fk.php @@ -12,6 +12,11 @@ */ public function up(): void { + // Only proceed if table exists (for backward compatibility) + if (!Schema::hasTable('buku_tamu')) { + return; + } + Schema::table('buku_tamu', function (Blueprint $table) { // Drop old FK if exists try { @@ -20,14 +25,20 @@ public function up(): void // Ignore } - // Change column type - DB::statement('ALTER TABLE buku_tamu MODIFY id_user BIGINT UNSIGNED NOT NULL'); + try { + $table->dropForeign(['id_user']); + } catch (\Exception $e) { + // Ignore if FK doesn't exist + } + + // Change column type if needed + DB::statement('ALTER TABLE buku_tamu MODIFY id_user BIGINT UNSIGNED NULL'); // Add correct FK $table->foreign('id_user') - ->references('id') - ->on('users') - ->onDelete('cascade'); + ->references('id') + ->on('users') + ->onDelete('set null'); }); } diff --git a/database/migrations/2026_03_03_160100_add_guest_fields_to_buku_tamu.php b/database/migrations/2026_03_03_160100_add_guest_fields_to_buku_tamu.php index 098d3c1..9c0834f 100644 --- a/database/migrations/2026_03_03_160100_add_guest_fields_to_buku_tamu.php +++ b/database/migrations/2026_03_03_160100_add_guest_fields_to_buku_tamu.php @@ -8,21 +8,12 @@ { public function up(): void { - Schema::table('buku_tamu', function (Blueprint $table) { - // id_user jadi nullable (tamu non-member tidak punya user) - $table->unsignedBigInteger('id_user')->nullable()->change(); - - // Kolom untuk tamu non-member - $table->string('nama_tamu')->nullable()->after('id_user'); - $table->string('asal_instansi')->nullable()->after('nama_tamu'); - }); + // Columns already exist in create_buku_tamu_table migration + // This migration is now a no-op for forward compatibility } public function down(): void { - Schema::table('buku_tamu', function (Blueprint $table) { - $table->dropColumn(['nama_tamu', 'asal_instansi']); - $table->unsignedBigInteger('id_user')->nullable(false)->change(); - }); + // No-op } }; diff --git a/database/migrations/2026_03_30_012100_add_missing_columns_to_buku_tamu_table.php b/database/migrations/2026_03_30_012100_add_missing_columns_to_buku_tamu_table.php index e8ae340..9c07236 100644 --- a/database/migrations/2026_03_30_012100_add_missing_columns_to_buku_tamu_table.php +++ b/database/migrations/2026_03_30_012100_add_missing_columns_to_buku_tamu_table.php @@ -11,11 +11,8 @@ */ public function up(): void { - Schema::table('buku_tamu', function (Blueprint $table) { - $table->string('email')->nullable()->after('nama_tamu'); - $table->string('no_hp')->nullable()->after('email'); - $table->string('status')->nullable()->after('asal_instansi'); - }); + // Columns already exist in create_buku_tamu_table migration + // This migration is now a no-op for forward compatibility } /** @@ -23,8 +20,6 @@ public function up(): void */ public function down(): void { - Schema::table('buku_tamu', function (Blueprint $table) { - $table->dropColumn(['email', 'no_hp', 'status']); - }); + // No-op } }; diff --git a/database/migrations/2026_04_02_000001_add_lokasi_to_buku_table.php b/database/migrations/2026_04_02_000001_add_lokasi_to_buku_table.php index 3640c2f..b4577e3 100644 --- a/database/migrations/2026_04_02_000001_add_lokasi_to_buku_table.php +++ b/database/migrations/2026_04_02_000001_add_lokasi_to_buku_table.php @@ -7,15 +7,19 @@ return new class extends Migration { public function up(): void { - Schema::table('buku', function (Blueprint $table) { - $table->float('lokasi_x')->nullable()->after('cover')->comment('Posisi X pin pada denah (persentase 0-100)'); - $table->float('lokasi_y')->nullable()->after('lokasi_x')->comment('Posisi Y pin pada denah (persentase 0-100)'); + Schema::table('bukus', function (Blueprint $table) { + if (!Schema::hasColumn('bukus', 'lokasi_x')) { + $table->float('lokasi_x')->nullable()->comment('Posisi X pin pada denah (persentase 0-100)'); + } + if (!Schema::hasColumn('bukus', 'lokasi_y')) { + $table->float('lokasi_y')->nullable()->comment('Posisi Y pin pada denah (persentase 0-100)'); + } }); } public function down(): void { - Schema::table('buku', function (Blueprint $table) { + Schema::table('bukus', function (Blueprint $table) { $table->dropColumn(['lokasi_x', 'lokasi_y']); }); }