mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 14:52:09 +00:00
Keep guest rooms moderated and restore owner moderation
This commit is contained in:
@@ -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.
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user