Keep guest rooms moderated and restore owner moderation
CI/CD / test_and_check_app (push) Successful in 2m22s
CI/CD / Publish immutable image (push) Successful in 1m16s

This commit is contained in:
2026-09-24 15:02:05 +02:00
parent 4dfe79ce5c
commit 33df9e49ab
6 changed files with 267 additions and 11 deletions
@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
DB::table('rooms')
->whereNull('owner_id')
->whereNull('deleted_at')
->whereNotIn('id', DB::table('players')->select('room_id'))
->update(['deleted_at' => now()]);
DB::table('rooms')
->whereNull('owner_id')
->whereNull('deleted_at')
->whereNotIn('id', DB::table('players')->where('is_moderator', true)->select('room_id'))
->select('id')
->chunkById(100, function ($rooms): void {
foreach ($rooms as $room) {
$playerId = DB::table('players')
->where('room_id', $room->id)
->orderBy('created_at')
->orderBy('id')
->value('id');
if ($playerId !== null) {
DB::table('players')
->where('id', $playerId)
->update(['is_moderator' => true]);
}
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
// Deleted rooms and former moderator assignments cannot be reconstructed.
}
};