whereNotNull('notes') ->where('notes', '<>', '') ->orderBy('id') ->chunkById(100, function ($calls) use (&$created): void { foreach ($calls as $call) { $note = Note::firstOrCreate( ['source_key' => "legacy_call:{$call->id}"], [ 'notable_type' => Call::class, 'notable_id' => $call->id, 'user_id' => $call->user_id, 'content' => $call->notes, 'type' => 'call_summary', 'visibility' => 'team', 'is_pinned' => false, 'created_at' => $call->updated_at ?? $call->created_at ?? now(), 'updated_at' => $call->updated_at ?? now(), ] ); $created += $note->wasRecentlyCreated ? 1 : 0; } }); return $created; } }