Make complaints master migration idempotent for existing codes
This commit is contained in:
parent
3e810dec74
commit
d2400fc5c2
|
|
@ -124,7 +124,24 @@ class CreateComplaintsMasterTable extends Migration
|
|||
unset($row);
|
||||
|
||||
if (! empty($rows)) {
|
||||
$this->db->table('complaints_master')->insertBatch($rows);
|
||||
$existingCodes = $this->db->table('complaints_master')
|
||||
->select('Code')
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
$existingCodeMap = [];
|
||||
foreach ($existingCodes as $existing) {
|
||||
$existingCodeMap[(int) ($existing['Code'] ?? 0)] = true;
|
||||
}
|
||||
|
||||
$newRows = array_values(array_filter(
|
||||
$rows,
|
||||
static fn(array $row): bool => ! isset($existingCodeMap[(int) ($row['Code'] ?? 0)])
|
||||
));
|
||||
|
||||
if (! empty($newRows)) {
|
||||
$this->db->table('complaints_master')->insertBatch($newRows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user