perf: add composite index on user_workspace(workspace_id, role) #51

Open
Charon wants to merge 1 commit from feat/add-workspace-role-index into dev

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add composite index on user_workspace(workspace_id, role).
*
* Fixes #11: queries like "get all owners of workspace X" previously
* required a full table scan. This composite index covers lookups
* filtering by workspace_id and role together.
*/
public function up(): void
{
Schema::table('user_workspace', function (Blueprint $table) {
$table->index(['workspace_id', 'role'], 'user_workspace_workspace_role_idx');
});
}
public function down(): void
{
Schema::table('user_workspace', function (Blueprint $table) {
$table->dropIndex('user_workspace_workspace_role_idx');
});
}
};