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