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:
parent
c51e4310b1
commit
39adfd67b0
1 changed files with 31 additions and 0 deletions
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue