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.
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('account_balances', function (Blueprint $table) {
|
||||||
|
// First drop the unique constraint since we'll be making these columns the primary key
|
||||||
|
$table->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']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user