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

Queries filtering by workspace_id and role (e.g. "get all owners of
workspace X") required a full table scan on the user_workspace pivot
table. This adds a composite index to cover those lookups efficiently.

Fixes #11

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude 2026-03-24 13:03:27 +00:00
parent c51e4310b1
commit 39adfd67b0
No known key found for this signature in database
GPG key ID: AF404715446AEB41

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');
});
}
};