From 2e2c8b4b0d4d91c0c53cc6ec00ef9ce6032d41c3 Mon Sep 17 00:00:00 2001 From: daengdeni Date: Sat, 24 May 2025 08:27:35 +0700 Subject: [PATCH] refactor(database): remove id from account_balances table - Menghapus kolom `id` dari tabel `account_balances` termasuk primary key auto-increment-nya. - Menjadikan kolom `account_number` dan `period` sebagai composite primary key. - Menghapus constraint unik pada kolom `account_number` dan `period`. - Menambahkan kembali kolom `id` dan constraint unik pada proses rollback. - Memastikan mendukung migrasi maju dan mundur dengan aman. --- ..._remove_id_from_account_balances_table.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 database/migrations/2025_05_24_082504_remove_id_from_account_balances_table.php diff --git a/database/migrations/2025_05_24_082504_remove_id_from_account_balances_table.php b/database/migrations/2025_05_24_082504_remove_id_from_account_balances_table.php new file mode 100644 index 0000000..b26da39 --- /dev/null +++ b/database/migrations/2025_05_24_082504_remove_id_from_account_balances_table.php @@ -0,0 +1,42 @@ +dropUnique(['account_number', 'period']); + + // Drop the id column and its auto-increment primary key + $table->dropColumn('id'); + + // Set the composite primary key + $table->primary(['account_number', 'period']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('account_balances', function (Blueprint $table) { + // Drop the composite primary key + $table->dropPrimary(['account_number', 'period']); + + // Add back the id column with auto-increment + $table->id()->first(); + + // Re-add the unique constraint + $table->unique(['account_number', 'period']); + }); + } + };