Chunk the migration

This commit is contained in:
Anil Kulkarni 2025-01-17 23:10:10 -08:00
parent bbc802ff8c
commit 587eb2665f
No known key found for this signature in database
GPG key ID: 4806669421E998D3

View file

@ -4,16 +4,24 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Status;
return new class extends Migration
{
public function up(): void
{
DB::table('statuses')
->leftJoin('profiles', 'statuses.profile_id', '=', 'profiles.id')
->leftJoin('users', 'users.profile_id', '=', 'profiles.id')
->whereNull('users.id')
->update(['local' => false]);
Status::query()
->where('local', true)
->where('type', 'share')
->whereHas('profile', function($query) {
$query->whereDoesntHave('user');
})
->chunkById(100, function($statuses) {
foreach($statuses as $status) {
$status->local = false;
$status->save();
}
});
}
public function down(): void