fix(migrations): make all package migrations idempotent
Some checks are pending
CI / PHP 8.2 (push) Waiting to run
CI / PHP 8.3 (push) Waiting to run
CI / PHP 8.4 (push) Waiting to run
CI / Assets (push) Waiting to run

Guard every Schema::create() with hasTable() so migrations
coexist safely with the consolidated app-level migration in
host.uk.com. Prevents "table already exists" failures that
would block the entire migration batch.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-02-08 21:07:59 +00:00
parent 8c2a532899
commit 2458f87c8d
5 changed files with 143 additions and 129 deletions

View file

@ -8,6 +8,7 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('mcp_api_requests')) {
Schema::create('mcp_api_requests', function (Blueprint $table) {
$table->id();
$table->string('request_id', 32)->unique();
@ -32,6 +33,7 @@ return new class extends Migration
$table->index('response_status');
});
}
}
public function down(): void
{

View file

@ -8,6 +8,7 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('mcp_tool_metrics')) {
Schema::create('mcp_tool_metrics', function (Blueprint $table) {
$table->id();
$table->string('tool_name');
@ -24,8 +25,10 @@ return new class extends Migration
$table->index(['date', 'tool_name']);
$table->index('workspace_id');
});
}
// Table for tracking tool combinations (tools used together in sessions)
if (! Schema::hasTable('mcp_tool_combinations')) {
Schema::create('mcp_tool_combinations', function (Blueprint $table) {
$table->id();
$table->string('tool_a');
@ -39,6 +42,7 @@ return new class extends Migration
$table->index(['date', 'occurrence_count']);
});
}
}
public function down(): void
{

View file

@ -8,6 +8,7 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('mcp_usage_quotas')) {
Schema::create('mcp_usage_quotas', function (Blueprint $table) {
$table->id();
$table->foreignId('workspace_id')->constrained('workspaces')->cascadeOnDelete();
@ -21,6 +22,7 @@ return new class extends Migration
$table->index('month');
});
}
}
public function down(): void
{

View file

@ -8,6 +8,7 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('mcp_audit_logs')) {
Schema::create('mcp_audit_logs', function (Blueprint $table) {
$table->id();
@ -58,8 +59,10 @@ return new class extends Migration
$table->index(['is_sensitive', 'created_at']);
$table->index(['actor_type', 'actor_id']);
});
}
// Table for tracking sensitive tool definitions
if (! Schema::hasTable('mcp_sensitive_tools')) {
Schema::create('mcp_sensitive_tools', function (Blueprint $table) {
$table->id();
$table->string('tool_name')->unique();
@ -69,6 +72,7 @@ return new class extends Migration
$table->timestamps();
});
}
}
public function down(): void
{

View file

@ -8,6 +8,7 @@ return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('mcp_tool_versions')) {
Schema::create('mcp_tool_versions', function (Blueprint $table) {
$table->id();
$table->string('server_id', 64)->index();
@ -33,6 +34,7 @@ return new class extends Migration
$table->index(['deprecated_at', 'sunset_at'], 'mcp_tool_versions_lifecycle');
});
}
}
public function down(): void
{