mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 15:32:09 +00:00
feat: some fixes to the ui, imlemented user and guest user, ans used the dahboard
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('rooms', function (Blueprint $table) {
|
||||
$table->foreignId('owner_id')
|
||||
->nullable()
|
||||
->after('id')
|
||||
->constrained('users')
|
||||
->nullOnDelete();
|
||||
$table->timestamp('last_activity_at')->nullable()->after('state_version')->index();
|
||||
$table->timestamp('closed_at')->nullable()->after('last_activity_at')->index();
|
||||
});
|
||||
|
||||
DB::table('rooms')
|
||||
->whereNull('last_activity_at')
|
||||
->update(['last_activity_at' => DB::raw('updated_at')]);
|
||||
|
||||
$moderators = DB::table('players')
|
||||
->where('is_moderator', true)
|
||||
->whereNotNull('user_id')
|
||||
->orderBy('id')
|
||||
->get(['room_id', 'user_id'])
|
||||
->unique('room_id');
|
||||
|
||||
foreach ($moderators as $moderator) {
|
||||
DB::table('rooms')
|
||||
->where('id', $moderator->room_id)
|
||||
->whereNull('owner_id')
|
||||
->update(['owner_id' => $moderator->user_id]);
|
||||
}
|
||||
|
||||
$duplicateMemberships = DB::table('players')
|
||||
->select(['room_id', 'user_id'])
|
||||
->whereNotNull('user_id')
|
||||
->groupBy('room_id', 'user_id')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->get();
|
||||
|
||||
foreach ($duplicateMemberships as $membership) {
|
||||
$players = DB::table('players')
|
||||
->where('room_id', $membership->room_id)
|
||||
->where('user_id', $membership->user_id)
|
||||
->orderByDesc('is_moderator')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
$canonicalPlayer = $players->first();
|
||||
|
||||
if ($canonicalPlayer === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$playerIds = $players->pluck('id');
|
||||
|
||||
DB::table('votes')
|
||||
->whereIn('player_id', $playerIds)
|
||||
->orderBy('updated_at')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->each(function (object $vote) use ($canonicalPlayer): void {
|
||||
DB::table('votes')->updateOrInsert(
|
||||
[
|
||||
'player_id' => $canonicalPlayer->id,
|
||||
'room_id' => $vote->room_id,
|
||||
'round' => $vote->round,
|
||||
],
|
||||
[
|
||||
'value' => $vote->value,
|
||||
'created_at' => $vote->created_at,
|
||||
'updated_at' => $vote->updated_at,
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
$duplicatePlayerIds = $playerIds
|
||||
->reject(fn (int $playerId): bool => $playerId === $canonicalPlayer->id)
|
||||
->values();
|
||||
|
||||
if ($duplicatePlayerIds->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::table('votes')->whereIn('player_id', $duplicatePlayerIds)->delete();
|
||||
DB::table('players')->whereIn('id', $duplicatePlayerIds)->delete();
|
||||
}
|
||||
|
||||
Schema::table('players', function (Blueprint $table) {
|
||||
$table->unique(['room_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('players', function (Blueprint $table) {
|
||||
$table->dropUnique(['room_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::table('rooms', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('owner_id');
|
||||
$table->dropColumn(['last_activity_at', 'closed_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('rooms', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('rooms', function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user