fix(webstatement): ubah metode upsert menjadi updateOrCreate pada ProcessStmtEntryDataJob

- Refactor proses penyimpanan data pada `ProcessStmtEntryDataJob`:
  - Mengganti metode `StmtEntry::upsert` dengan `StmtEntry::updateOrCreate` untuk setiap entri dalam batch.
  - Metode `updateOrCreate` memungkinkan pembaruan data atau penyisipan data baru berdasarkan `stmt_entry_id` sebagai kunci unik.
- Meningkatkan fleksibilitas pembaruan data dengan menggunakan loop per entry dibandingkan bulk operation, sehingga lebih kompatibel untuk kasus tertentu.

- Tambahkan file migrasi baru untuk penyesuaian tabel `stmt_entry`:
  - File migrasi telah dibuat sebagai dasar, namun implementasi detail dalam tabel masih kosong.
  - File ini akan digunakan untuk perubahan skema di masa mendatang sesuai kebutuhan pengembangan.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
Daeng Deni Mardaeni
2025-05-29 19:40:35 +07:00
parent eed6c3dbaa
commit 76ebdce2ea
2 changed files with 34 additions and 6 deletions

View File

@@ -191,12 +191,12 @@
{
try {
if (!empty($this->entryBatch)) {
// Bulk insert/update statement entries
StmtEntry::upsert(
$this->entryBatch,
['stmt_entry_id'], // Unique key
array_diff((new StmtEntry())->getFillable(), ['stmt_entry_id']) // Update columns
);
foreach ($this->entryBatch as $entry) {
StmtEntry::updateOrCreate(
['stmt_entry_id' => $entry['stmt_entry_id']], // Find by this key
$entry // Update or create with these values
);
}
// Reset entry batch after processing
$this->entryBatch = [];

View File

@@ -0,0 +1,28 @@
<?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('stmt_entry', function (Blueprint $table) {
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('stmt_entry', function (Blueprint $table) {
});
}
};