<?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
    {
        \DB::table('deals')->whereNotNull('client_id')->orderBy('id')->chunk(1000, function ($rows)
        {
            foreach ($rows as $row)
            {
                \DB::table('deal_clients')->updateOrInsert(['deal_id' => $row->id, 'client_id' => $row->client_id]);
                // Or if you're creating new records in the new table based on the old, use insert:
                // \DB::table('new_table_name')->insert(['id' => $row->id, 'field_name' => $row->field_name]);
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {

    }
};
