refactor(database): update primary key in processed_statements table
- Menghapus kolom `id` dari tabel `processed_statements` dan sekaligus menghapus primary key auto-increment terkait. - Menetapkan kombinasi kolom `account_number`, `period`, dan `sequence_no` sebagai keys baru dengan composite primary key untuk memastikan setiap record bersifat unik. - Menambahkan kemampuan rollback pada migration untuk mengembalikan struktur ke kondisi awal: - Menghapus composite primary key pada kolom `account_number`, `period`, dan `sequence_no`. - Menambahkan kembali kolom `id` sebagai auto-increment primary key di posisi paling awal tabel.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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('processed_statements', function (Blueprint $table) {
|
||||
// Drop the id column and its auto-increment primary key
|
||||
$table->dropColumn('id');
|
||||
|
||||
// Set the composite primary key using account_number, period, and sequence_no
|
||||
// This combination should be unique for each record
|
||||
$table->primary(['account_number', 'period', 'sequence_no']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('processed_statements', function (Blueprint $table) {
|
||||
// Drop the composite primary key
|
||||
$table->dropPrimary(['account_number', 'period', 'sequence_no']);
|
||||
|
||||
// Add back the id column with auto-increment
|
||||
$table->id()->first();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user