kopia lustrzana https://github.com/pixelfed/pixelfed
Refactor migration
rodzic
d97383c0f6
commit
3109e6a1ab
|
|
@ -4,24 +4,18 @@ use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Models\Status;
|
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Status::query()
|
DB::table('statuses')
|
||||||
->where('local', true)
|
->join('profiles', 'profiles.id', '=', 'statuses.profile_id')
|
||||||
->where('type', 'share')
|
->leftJoin('users', 'users.id', '=', 'profiles.user_id')
|
||||||
->whereHas('profile', function($query) {
|
->where('statuses.local', true)
|
||||||
$query->whereDoesntHave('user');
|
->where('statuses.type', 'share')
|
||||||
})
|
->whereNull('users.id')
|
||||||
->chunkById(100, function($statuses) {
|
->update(['statuses.local' => false]);
|
||||||
foreach($statuses as $status) {
|
|
||||||
$status->local = false;
|
|
||||||
$status->save();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue