mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-02-02 09:50:46 +00:00
Chunk the migration
This commit is contained in:
parent
bbc802ff8c
commit
587eb2665f
1 changed files with 13 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue