fix(migrations): make all package migrations idempotent
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:
parent
8c2a532899
commit
2458f87c8d
5 changed files with 143 additions and 129 deletions
|
|
@ -8,6 +8,7 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('mcp_api_requests')) {
|
||||||
Schema::create('mcp_api_requests', function (Blueprint $table) {
|
Schema::create('mcp_api_requests', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('request_id', 32)->unique();
|
$table->string('request_id', 32)->unique();
|
||||||
|
|
@ -32,6 +33,7 @@ return new class extends Migration
|
||||||
$table->index('response_status');
|
$table->index('response_status');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('mcp_tool_metrics')) {
|
||||||
Schema::create('mcp_tool_metrics', function (Blueprint $table) {
|
Schema::create('mcp_tool_metrics', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('tool_name');
|
$table->string('tool_name');
|
||||||
|
|
@ -24,8 +25,10 @@ return new class extends Migration
|
||||||
$table->index(['date', 'tool_name']);
|
$table->index(['date', 'tool_name']);
|
||||||
$table->index('workspace_id');
|
$table->index('workspace_id');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Table for tracking tool combinations (tools used together in sessions)
|
// Table for tracking tool combinations (tools used together in sessions)
|
||||||
|
if (! Schema::hasTable('mcp_tool_combinations')) {
|
||||||
Schema::create('mcp_tool_combinations', function (Blueprint $table) {
|
Schema::create('mcp_tool_combinations', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('tool_a');
|
$table->string('tool_a');
|
||||||
|
|
@ -39,6 +42,7 @@ return new class extends Migration
|
||||||
$table->index(['date', 'occurrence_count']);
|
$table->index(['date', 'occurrence_count']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('mcp_usage_quotas')) {
|
||||||
Schema::create('mcp_usage_quotas', function (Blueprint $table) {
|
Schema::create('mcp_usage_quotas', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('workspace_id')->constrained('workspaces')->cascadeOnDelete();
|
$table->foreignId('workspace_id')->constrained('workspaces')->cascadeOnDelete();
|
||||||
|
|
@ -21,6 +22,7 @@ return new class extends Migration
|
||||||
$table->index('month');
|
$table->index('month');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('mcp_audit_logs')) {
|
||||||
Schema::create('mcp_audit_logs', function (Blueprint $table) {
|
Schema::create('mcp_audit_logs', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
|
||||||
|
|
@ -58,8 +59,10 @@ return new class extends Migration
|
||||||
$table->index(['is_sensitive', 'created_at']);
|
$table->index(['is_sensitive', 'created_at']);
|
||||||
$table->index(['actor_type', 'actor_id']);
|
$table->index(['actor_type', 'actor_id']);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Table for tracking sensitive tool definitions
|
// Table for tracking sensitive tool definitions
|
||||||
|
if (! Schema::hasTable('mcp_sensitive_tools')) {
|
||||||
Schema::create('mcp_sensitive_tools', function (Blueprint $table) {
|
Schema::create('mcp_sensitive_tools', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('tool_name')->unique();
|
$table->string('tool_name')->unique();
|
||||||
|
|
@ -69,6 +72,7 @@ return new class extends Migration
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
|
if (! Schema::hasTable('mcp_tool_versions')) {
|
||||||
Schema::create('mcp_tool_versions', function (Blueprint $table) {
|
Schema::create('mcp_tool_versions', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('server_id', 64)->index();
|
$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');
|
$table->index(['deprecated_at', 'sunset_at'], 'mcp_tool_versions_lifecycle');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue