phase 6 added helpdesk

This commit is contained in:
Mark Gregory
2026-07-24 11:28:06 +01:00
parent 5ecf20fe97
commit 8c74abfbc6
212 changed files with 23064 additions and 0 deletions
@@ -0,0 +1,26 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', static function (Blueprint $table): void {
if (! Schema::hasColumn('users', 'helpdesk_agent')) {
$table->boolean('helpdesk_agent')->default(false)->after('password');
}
if (! Schema::hasColumn('users', 'helpdesk_admin')) {
$table->boolean('helpdesk_admin')->default(false)->after('helpdesk_agent');
}
});
}
};
@@ -0,0 +1,73 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_statuses', static function (Blueprint $table): void {
$table->id();
$table->string('name', 80);
$table->string('slug', 100)->unique();
$table->string('color', 30)->default('zinc');
$table->unsignedSmallInteger('sort_order')->default(0);
$table->boolean('is_closed')->default(false);
$table->timestamps();
});
Schema::create('helpdesk_priorities', static function (Blueprint $table): void {
$table->id();
$table->string('name', 80);
$table->string('slug', 100)->unique();
$table->string('color', 30)->default('zinc');
$table->unsignedSmallInteger('sort_order')->default(0);
$table->timestamps();
});
Schema::create('helpdesk_categories', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->string('name', 120);
$table->string('slug', 140);
$table->string('color', 30)->default('blue');
$table->text('description')->nullable();
$table->timestamps();
$table->unique(['company_id', 'slug']);
});
Schema::create('helpdesk_teams', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->string('name', 120);
$table->string('slug', 140);
$table->string('color', 30)->default('indigo');
$table->text('description')->nullable();
$table->timestamp('archived_at')->nullable();
$table->softDeletes();
$table->timestamps();
$table->unique(['company_id', 'slug']);
});
Schema::create('helpdesk_projects', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
$table->string('title', 160);
$table->string('slug', 180);
$table->string('color', 30)->default('blue');
$table->text('description')->nullable();
$table->timestamp('archived_at')->nullable();
$table->softDeletes();
$table->timestamps();
$table->unique(['company_id', 'slug']);
});
}
};
@@ -0,0 +1,41 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_tickets', static function (Blueprint $table): void {
$table->id();
$table->string('reference', 32)->unique();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->foreignId('agent_id')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('status_id')->constrained('helpdesk_statuses')->restrictOnDelete();
$table->foreignId('priority_id')->constrained('helpdesk_priorities')->restrictOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
$table->string('subject', 200);
$table->longText('body');
$table->timestamp('due_at')->nullable();
$table->timestamp('completed_at')->nullable();
$table->timestamp('last_activity_at')->nullable();
$table->timestamp('archived_at')->nullable();
$table->softDeletes();
$table->timestamps();
$table->index(['company_id', 'project_id']);
$table->index(['team_id', 'status_id']);
$table->index(['status_id', 'priority_id']);
$table->index(['agent_id', 'completed_at']);
$table->index(['user_id', 'created_at']);
$table->index('last_activity_at');
});
}
};
@@ -0,0 +1,78 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_git_repositories', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
$table->string('name', 160);
$table->string('provider', 40)->default('git');
$table->string('remote_url', 500);
$table->string('default_branch', 120)->default('main');
$table->string('webhook_secret', 120)->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index(['company_id', 'project_id']);
$table->index(['provider', 'is_active']);
});
Schema::create('helpdesk_git_commits', static function (Blueprint $table): void {
$table->id();
$table->foreignId('repository_id')->constrained('helpdesk_git_repositories')->cascadeOnDelete();
$table->foreignId('ticket_id')->nullable()->constrained('helpdesk_tickets')->nullOnDelete();
$table->string('hash', 80);
$table->string('short_hash', 16);
$table->string('branch', 120)->nullable();
$table->string('author_name', 160)->nullable();
$table->string('author_email', 190)->nullable();
$table->text('message');
$table->string('url', 500)->nullable();
$table->timestamp('committed_at')->nullable();
$table->timestamps();
$table->unique(['repository_id', 'hash']);
$table->index(['ticket_id', 'committed_at']);
});
Schema::create('helpdesk_workflow_templates', static function (Blueprint $table): void {
$table->id();
$table->string('name', 160);
$table->string('event', 80);
$table->string('subject', 220);
$table->longText('html_body');
$table->longText('text_body')->nullable();
$table->string('to_role', 40)->default('requester');
$table->string('cc', 500)->nullable();
$table->string('bcc', 500)->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index(['event', 'is_active']);
});
Schema::create('helpdesk_workflow_logs', static function (Blueprint $table): void {
$table->id();
$table->foreignId('template_id')->nullable()->constrained('helpdesk_workflow_templates')->nullOnDelete();
$table->foreignId('ticket_id')->nullable()->constrained('helpdesk_tickets')->nullOnDelete();
$table->string('event', 80);
$table->string('recipient', 190)->nullable();
$table->string('subject', 220)->nullable();
$table->string('status', 40)->default('pending');
$table->text('error')->nullable();
$table->timestamps();
$table->index(['ticket_id', 'event']);
$table->index(['status', 'created_at']);
});
}
};
@@ -0,0 +1,40 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_comments', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('parent_id')->nullable()->constrained('helpdesk_comments')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->longText('body');
$table->boolean('is_internal')->default(false);
$table->timestamps();
$table->index(['ticket_id', 'parent_id', 'created_at']);
});
Schema::create('helpdesk_attachments', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('comment_id')->nullable()->constrained('helpdesk_comments')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
$table->string('disk', 80);
$table->string('path', 500);
$table->string('original_name', 255);
$table->string('mime_type', 160)->nullable();
$table->unsignedBigInteger('size')->default(0);
$table->timestamps();
$table->index(['ticket_id', 'comment_id', 'created_at']);
});
}
};
@@ -0,0 +1,21 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_category_user', static function (Blueprint $table): void {
$table->id();
$table->foreignId('category_id')->constrained('helpdesk_categories')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->timestamps();
$table->unique(['category_id', 'user_id']);
});
}
};
@@ -0,0 +1,39 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_kanban_boards')) {
Schema::create('helpdesk_kanban_boards', function (Blueprint $table): void {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->boolean('is_default')->default(false);
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->softDeletes();
$table->index(['is_default', 'sort_order']);
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('helpdesk_kanban_boards');
}
};
@@ -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
{
public function up(): void
{
if (! Schema::hasTable('helpdesk_kanban_board_statuses')) {
Schema::create('helpdesk_kanban_board_statuses', function (Blueprint $table): void {
$table->id();
$table->foreignId('board_id')->constrained('helpdesk_kanban_boards')->cascadeOnDelete();
$table->foreignId('status_id')->constrained('helpdesk_statuses')->cascadeOnDelete();
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->unique(['board_id', 'status_id']);
$table->index(['board_id', 'sort_order']);
});
}
}
public function down(): void
{
Schema::dropIfExists('helpdesk_kanban_board_statuses');
}
};
@@ -0,0 +1,205 @@
<?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
{
public function up(): void
{
Schema::create('helpdesk_products', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->string('name', 160);
$table->string('slug', 180);
$table->string('type', 60)->default('service');
$table->string('version', 80)->nullable();
$table->string('release_channel', 80)->nullable();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->unique(['company_id', 'slug']);
});
Schema::create('helpdesk_sla_policies', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('priority_id')->nullable()->constrained('helpdesk_priorities')->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->string('name', 160);
$table->string('slug', 180);
$table->unsignedInteger('first_response_minutes')->default(240);
$table->unsignedInteger('resolution_minutes')->default(2880);
$table->boolean('business_hours_only')->default(false);
$table->boolean('is_default')->default(false);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->unique(['company_id', 'slug']);
$table->index(['priority_id', 'category_id', 'is_active']);
});
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_tickets', 'sla_policy_id')) {
$table->foreignId('sla_policy_id')->nullable()->after('team_id')->constrained('helpdesk_sla_policies')->nullOnDelete();
}
if (! Schema::hasColumn('helpdesk_tickets', 'product_id')) {
$table->foreignId('product_id')->nullable()->after('project_id')->constrained('helpdesk_products')->nullOnDelete();
}
if (! Schema::hasColumn('helpdesk_tickets', 'first_response_at')) {
$table->timestamp('first_response_at')->nullable()->after('due_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'sla_first_response_due_at')) {
$table->timestamp('sla_first_response_due_at')->nullable()->after('first_response_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'sla_resolution_due_at')) {
$table->timestamp('sla_resolution_due_at')->nullable()->after('sla_first_response_due_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'sla_first_response_breached_at')) {
$table->timestamp('sla_first_response_breached_at')->nullable()->after('sla_resolution_due_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'sla_resolution_breached_at')) {
$table->timestamp('sla_resolution_breached_at')->nullable()->after('sla_first_response_breached_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'public_replies_count')) {
$table->unsignedInteger('public_replies_count')->default(0)->after('sla_resolution_breached_at');
}
if (! Schema::hasColumn('helpdesk_tickets', 'time_spent_minutes')) {
$table->unsignedInteger('time_spent_minutes')->default(0)->after('public_replies_count');
}
$table->index(['sla_policy_id', 'sla_resolution_due_at'], 'helpdesk_tickets_sla_policy_due_idx');
$table->index(['product_id', 'completed_at'], 'helpdesk_tickets_product_closed_idx');
});
Schema::table('helpdesk_workflow_logs', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_workflow_logs', 'tracking_token')) {
$table->string('tracking_token', 64)->nullable()->unique()->after('status');
}
if (! Schema::hasColumn('helpdesk_workflow_logs', 'first_opened_at')) {
$table->timestamp('first_opened_at')->nullable()->after('tracking_token');
}
if (! Schema::hasColumn('helpdesk_workflow_logs', 'last_opened_at')) {
$table->timestamp('last_opened_at')->nullable()->after('first_opened_at');
}
if (! Schema::hasColumn('helpdesk_workflow_logs', 'opened_count')) {
$table->unsignedInteger('opened_count')->default(0)->after('last_opened_at');
}
});
Schema::create('helpdesk_canned_responses', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
$table->string('name', 160);
$table->string('slug', 180);
$table->string('visibility', 40)->default('agents');
$table->string('subject', 220)->nullable();
$table->longText('body');
$table->boolean('is_active')->default(true);
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->unique(['company_id', 'slug']);
$table->index(['category_id', 'team_id', 'is_active']);
});
Schema::create('helpdesk_automation_rules', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->string('name', 160);
$table->string('slug', 180);
$table->string('match_sender', 190)->nullable();
$table->string('match_subject', 220)->nullable();
$table->string('match_mailbox', 190)->nullable();
$table->foreignId('match_category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('set_priority_id')->nullable()->constrained('helpdesk_priorities')->nullOnDelete();
$table->foreignId('set_category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('set_team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
$table->foreignId('set_project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
$table->foreignId('set_status_id')->nullable()->constrained('helpdesk_statuses')->nullOnDelete();
$table->foreignId('set_agent_id')->nullable()->constrained('users')->nullOnDelete();
$table->boolean('is_active')->default(true);
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->unique(['company_id', 'slug']);
$table->index(['is_active', 'sort_order']);
});
Schema::create('helpdesk_ticket_sla_events', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('sla_policy_id')->nullable()->constrained('helpdesk_sla_policies')->nullOnDelete();
$table->string('event', 80);
$table->timestamp('due_at')->nullable();
$table->timestamp('occurred_at')->nullable();
$table->boolean('breached')->default(false);
$table->json('meta')->nullable();
$table->timestamps();
$table->index(['ticket_id', 'event']);
$table->index(['breached', 'due_at']);
});
Schema::create('helpdesk_ticket_ratings', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('agent_id')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('team_id')->nullable()->constrained('helpdesk_teams')->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->unsignedTinyInteger('rating');
$table->string('token', 80)->unique();
$table->text('comment')->nullable();
$table->timestamp('rated_at')->nullable();
$table->timestamps();
$table->index(['agent_id', 'rating']);
$table->index(['team_id', 'category_id']);
});
Schema::create('helpdesk_tags', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->string('name', 80);
$table->string('slug', 100);
$table->string('color', 30)->default('zinc');
$table->timestamps();
$table->unique(['company_id', 'slug']);
});
Schema::create('helpdesk_ticket_tag', static function (Blueprint $table): void {
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('tag_id')->constrained('helpdesk_tags')->cascadeOnDelete();
$table->primary(['ticket_id', 'tag_id']);
});
Schema::create('helpdesk_checklist_templates', static function (Blueprint $table): void {
$table->id();
$table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained('helpdesk_categories')->nullOnDelete();
$table->foreignId('project_id')->nullable()->constrained('helpdesk_projects')->nullOnDelete();
$table->string('name', 160);
$table->string('slug', 180);
$table->json('items');
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->unique(['company_id', 'slug']);
$table->index(['category_id', 'project_id', 'is_active']);
});
Schema::create('helpdesk_checklist_items', static function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('template_id')->nullable()->constrained('helpdesk_checklist_templates')->nullOnDelete();
$table->string('title', 220);
$table->text('description')->nullable();
$table->boolean('is_completed')->default(false);
$table->foreignId('completed_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('completed_at')->nullable();
$table->unsignedInteger('sort_order')->default(0);
$table->timestamps();
$table->index(['ticket_id', 'is_completed']);
});
}
};
@@ -0,0 +1,39 @@
<?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 auditable Git webhook ingestion support.
*/
public function up(): void
{
if (Schema::hasTable('helpdesk_git_webhook_logs')) {
return;
}
Schema::create('helpdesk_git_webhook_logs', static function (Blueprint $table): void {
$table->id();
$table->foreignId('repository_id')->constrained('helpdesk_git_repositories')->cascadeOnDelete();
$table->string('provider', 40);
$table->string('delivery_id', 190)->nullable();
$table->string('event', 120)->nullable();
$table->string('status', 40)->default('accepted');
$table->string('message', 500)->nullable();
$table->unsignedInteger('commit_count')->default(0);
$table->unsignedInteger('linked_count')->default(0);
$table->unsignedInteger('ignored_count')->default(0);
$table->json('payload')->nullable();
$table->timestamp('received_at')->nullable();
$table->timestamps();
$table->index(['repository_id', 'status', 'received_at']);
$table->index(['provider', 'event']);
});
}
};
@@ -0,0 +1,48 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
foreach ([
'helpdesk_statuses',
'helpdesk_priorities',
'helpdesk_categories',
'helpdesk_projects',
'helpdesk_teams',
] as $table) {
if (! Schema::hasColumn($table, 'is_default')) {
Schema::table($table, function (Blueprint $table): void {
$table->boolean('is_default')->default(false);
});
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
foreach ([
'helpdesk_statuses',
'helpdesk_priorities',
'helpdesk_categories',
'helpdesk_projects',
'helpdesk_teams',
] as $tableName) {
if (Schema::hasColumn($tableName, 'is_default')) {
Schema::table($tableName, function (Blueprint $table): void {
$table->dropColumn('is_default');
});
}
}
}
};
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasColumn('companies', 'is_default_helpdesk_company')) {
Schema::table('companies', function (Blueprint $table): void {
$table->boolean('is_default_helpdesk_company')
->default(false)
->after('is_system_company');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (Schema::hasColumn('companies', 'is_default_helpdesk_company')) {
Schema::table('companies', function (Blueprint $table): void {
$table->dropColumn('is_default_helpdesk_company');
});
}
}
};
@@ -0,0 +1,50 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
foreach ([
'helpdesk_statuses',
'helpdesk_priorities',
'helpdesk_categories',
'helpdesk_projects',
'helpdesk_teams',
] as $tableName) {
if (Schema::hasTable($tableName) && ! Schema::hasColumn($tableName, 'is_default')) {
Schema::table($tableName, static function (Blueprint $table): void {
$table->boolean('is_default')->default(false);
});
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
foreach ([
'helpdesk_statuses',
'helpdesk_priorities',
'helpdesk_categories',
'helpdesk_projects',
'helpdesk_teams',
] as $tableName) {
if (Schema::hasTable($tableName) && Schema::hasColumn($tableName, 'is_default')) {
Schema::table($tableName, static function (Blueprint $table): void {
$table->dropColumn('is_default');
});
}
}
}
};
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add single-board ticket assignment and board ownership.
*/
public function up(): void
{
if (Schema::hasTable('helpdesk_kanban_boards') && ! Schema::hasColumn('helpdesk_kanban_boards', 'owner_id')) {
Schema::table('helpdesk_kanban_boards', static function (Blueprint $table): void {
$table->foreignId('owner_id')
->nullable()
->after('description')
->constrained('users')
->nullOnDelete();
$table->index('owner_id');
});
}
if (Schema::hasTable('helpdesk_tickets') && ! Schema::hasColumn('helpdesk_tickets', 'board_id')) {
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
$table->foreignId('board_id')
->nullable()
->after('status_id')
->constrained('helpdesk_kanban_boards')
->nullOnDelete();
$table->index(['board_id', 'status_id']);
});
}
if (Schema::hasTable('helpdesk_tickets') && Schema::hasTable('helpdesk_kanban_boards') && Schema::hasColumn('helpdesk_tickets', 'board_id')) {
$defaultBoardId = DB::table('helpdesk_kanban_boards')
->where('is_default', true)
->orderBy('sort_order')
->value('id') ?: DB::table('helpdesk_kanban_boards')->orderBy('sort_order')->value('id');
if ($defaultBoardId !== null) {
DB::table('helpdesk_tickets')
->whereNull('board_id')
->update(['board_id' => $defaultBoardId]);
}
}
}
/**
* Reverse the migration.
*/
public function down(): void
{
if (Schema::hasTable('helpdesk_tickets') && Schema::hasColumn('helpdesk_tickets', 'board_id')) {
Schema::table('helpdesk_tickets', static function (Blueprint $table): void {
$table->dropForeign(['board_id']);
$table->dropIndex(['board_id', 'status_id']);
$table->dropColumn('board_id');
});
}
if (Schema::hasTable('helpdesk_kanban_boards') && Schema::hasColumn('helpdesk_kanban_boards', 'owner_id')) {
Schema::table('helpdesk_kanban_boards', static function (Blueprint $table): void {
$table->dropForeign(['owner_id']);
$table->dropIndex(['owner_id']);
$table->dropColumn('owner_id');
});
}
}
};
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Ensure existing tickets have one concrete Kanban board assignment.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_tickets') || ! Schema::hasColumn('helpdesk_tickets', 'board_id')) {
return;
}
if (! Schema::hasTable('helpdesk_kanban_boards')) {
return;
}
$defaultBoardId = DB::table('helpdesk_kanban_boards')
->where('is_default', true)
->orderBy('sort_order')
->value('id') ?: DB::table('helpdesk_kanban_boards')->orderBy('sort_order')->value('id');
if ($defaultBoardId === null) {
return;
}
DB::table('helpdesk_tickets')
->whereNull('board_id')
->update([
'board_id' => $defaultBoardId,
'updated_at' => now(),
]);
DB::table('helpdesk_tickets')
->whereNotNull('board_id')
->whereNotExists(function ($query): void {
$query->selectRaw('1')
->from('helpdesk_kanban_boards')
->whereColumn('helpdesk_kanban_boards.id', 'helpdesk_tickets.board_id');
})
->update([
'board_id' => $defaultBoardId,
'updated_at' => now(),
]);
}
/**
* This data repair is intentionally not reversed.
*/
public function down(): void
{
// No-op: do not remove repaired board ownership from existing tickets.
}
};
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Backfill status columns for every Kanban board that currently has no columns.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_kanban_boards')
|| ! Schema::hasTable('helpdesk_kanban_board_statuses')
|| ! Schema::hasTable('helpdesk_statuses')) {
return;
}
$statuses = DB::table('helpdesk_statuses')
->orderBy('sort_order')
->orderBy('name')
->get(['id']);
if ($statuses->isEmpty()) {
return;
}
$boards = DB::table('helpdesk_kanban_boards')
->orderBy('sort_order')
->orderBy('name')
->get(['id']);
foreach ($boards as $board) {
$hasColumns = DB::table('helpdesk_kanban_board_statuses')
->where('board_id', $board->id)
->exists();
if ($hasColumns) {
continue;
}
foreach ($statuses as $index => $status) {
DB::table('helpdesk_kanban_board_statuses')->updateOrInsert(
['board_id' => $board->id, 'status_id' => $status->id],
[
'sort_order' => ($index + 1) * 10,
'created_at' => now(),
'updated_at' => now(),
],
);
}
}
}
/**
* The migration only repairs missing board columns and is intentionally not destructive.
*/
public function down(): void
{
// No-op. Do not remove configured board columns.
}
};
@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Modules\Helpdesk\Models\Comment;
return new class extends Migration
{
public function up(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_comments', 'guid')) {
$table->uuid('guid')->nullable()->after('id');
}
if (! Schema::hasColumn('helpdesk_comments', 'unid')) {
$table->string('unid', 64)->nullable()->after('guid');
}
if (! Schema::hasColumn('helpdesk_comments', 'replica_id')) {
$table->string('replica_id', 64)->nullable()->after('unid');
}
if (! Schema::hasColumn('helpdesk_comments', 'parent_unid')) {
$table->string('parent_unid', 64)->nullable()->after('parent_id');
}
if (! Schema::hasColumn('helpdesk_comments', 'root_unid')) {
$table->string('root_unid', 64)->nullable()->after('parent_unid');
}
if (! Schema::hasColumn('helpdesk_comments', 'originator_id')) {
$table->string('originator_id', 96)->nullable()->after('root_unid');
}
if (! Schema::hasColumn('helpdesk_comments', 'sync_sequence')) {
$table->unsignedBigInteger('sync_sequence')->default(1)->after('originator_id');
}
if (! Schema::hasColumn('helpdesk_comments', 'sync_hash')) {
$table->string('sync_hash', 128)->nullable()->after('sync_sequence');
}
if (! Schema::hasColumn('helpdesk_comments', 'source_system')) {
$table->string('source_system', 80)->default('wms-helpdesk')->after('sync_hash');
}
if (! Schema::hasColumn('helpdesk_comments', 'source_record_id')) {
$table->string('source_record_id', 120)->nullable()->after('source_system');
}
if (! Schema::hasColumn('helpdesk_comments', 'body_text')) {
$table->text('body_text')->nullable()->after('body');
}
if (! Schema::hasColumn('helpdesk_comments', 'replicated_at')) {
$table->timestamp('replicated_at')->nullable()->after('updated_at');
}
if (! Schema::hasColumn('helpdesk_comments', 'synced_at')) {
$table->timestamp('synced_at')->nullable()->after('replicated_at');
}
if (! Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) {
$table->timestamp('tombstoned_at')->nullable()->after('synced_at');
}
});
Comment::query()->orderBy('id')->chunkById(100, static function ($comments): void {
foreach ($comments as $comment) {
$guid = $comment->guid ?: (string) Str::uuid();
$unid = $comment->unid ?: strtoupper(hash('sha256', $guid . '|' . $comment->ticket_id . '|' . $comment->id));
$parent = $comment->parent_id ? Comment::query()->find($comment->parent_id) : null;
$parentUnid = $parent?->unid;
$rootUnid = $parent?->root_unid ?: $parentUnid ?: $unid;
DB::table('helpdesk_comments')
->where('id', $comment->id)
->update([
'guid' => $guid,
'unid' => $unid,
'parent_unid' => $parentUnid,
'root_unid' => $rootUnid,
'originator_id' => $comment->originator_id ?: $unid . ':1',
'sync_sequence' => $comment->sync_sequence ?: 1,
'sync_hash' => hash('sha256', (string) $comment->body),
'body_text' => trim(strip_tags((string) $comment->body)),
'source_system' => $comment->source_system ?: 'wms-helpdesk',
]);
}
});
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
$table->unique('guid', 'helpdesk_comments_guid_unique');
$table->unique('unid', 'helpdesk_comments_unid_unique');
$table->index(['ticket_id', 'root_unid', 'parent_unid'], 'helpdesk_comments_lotus_thread_index');
$table->index(['ticket_id', 'is_internal', 'created_at'], 'helpdesk_comments_visibility_index');
});
}
public function down(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
$table->dropUnique('helpdesk_comments_guid_unique');
$table->dropUnique('helpdesk_comments_unid_unique');
$table->dropIndex('helpdesk_comments_lotus_thread_index');
$table->dropIndex('helpdesk_comments_visibility_index');
$table->dropColumn([
'guid',
'unid',
'replica_id',
'parent_unid',
'root_unid',
'originator_id',
'sync_sequence',
'sync_hash',
'source_system',
'source_record_id',
'body_text',
'replicated_at',
'synced_at',
'tombstoned_at',
]);
});
}
};
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
return new class extends Migration
{
public function up(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_comments', 'subject')) {
$table->string('subject', 180)->nullable()->after('user_id');
}
});
DB::table('helpdesk_comments')
->whereNull('subject')
->orWhere('subject', '')
->orderBy('id')
->select(['id', 'parent_id', 'body', 'body_text', 'is_internal'])
->chunkById(100, static function ($comments): void {
foreach ($comments as $comment) {
$plain = trim(preg_replace('/\s+/', ' ', strip_tags((string) ($comment->body_text ?: $comment->body))) ?: '');
$subject = (bool) $comment->is_internal
? 'Internal note'
: ((int) ($comment->parent_id ?? 0) > 0 ? 'RE: ' : '') . Str::limit($plain !== '' ? $plain : 'Response', 120, '');
DB::table('helpdesk_comments')
->where('id', $comment->id)
->update(['subject' => $subject]);
}
});
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
$table->index(['ticket_id', 'subject'], 'helpdesk_comments_ticket_subject_index');
});
}
public function down(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
if (Schema::hasColumn('helpdesk_comments', 'subject')) {
$table->dropIndex('helpdesk_comments_ticket_subject_index');
$table->dropColumn('subject');
}
});
}
};
@@ -0,0 +1,40 @@
<?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
{
public function up(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_comments', 'tombstoned_at')) {
$table->timestamp('tombstoned_at')->nullable()->after('synced_at');
}
if (! Schema::hasColumn('helpdesk_comments', 'deleted_by')) {
$table->foreignId('deleted_by')->nullable()->after('tombstoned_at')->constrained('users')->nullOnDelete();
}
if (! Schema::hasColumn('helpdesk_comments', 'delete_reason')) {
$table->string('delete_reason', 255)->nullable()->after('deleted_by');
}
});
}
public function down(): void
{
Schema::table('helpdesk_comments', static function (Blueprint $table): void {
if (Schema::hasColumn('helpdesk_comments', 'deleted_by')) {
$table->dropConstrainedForeignId('deleted_by');
}
if (Schema::hasColumn('helpdesk_comments', 'delete_reason')) {
$table->dropColumn('delete_reason');
}
});
}
};
@@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add persistent timer fields to the existing helpdesk time log table.
*/
public function up(): void
{
foreach (['helpdesk_time_logs', 'time_logs'] as $tableName) {
if (! Schema::hasTable($tableName)) {
continue;
}
Schema::table($tableName, function (Blueprint $table) use ($tableName): void {
if (! Schema::hasColumn($tableName, 'started_at')) {
$table->timestamp('started_at')->nullable()->after('logged_at');
}
if (! Schema::hasColumn($tableName, 'ended_at')) {
$table->timestamp('ended_at')->nullable()->after('started_at');
}
if (! Schema::hasColumn($tableName, 'duration_seconds')) {
$table->unsignedInteger('duration_seconds')->default(0)->after('minutes');
}
});
}
}
/**
* Remove persistent timer fields from the existing helpdesk time log table.
*/
public function down(): void
{
foreach (['helpdesk_time_logs', 'time_logs'] as $tableName) {
if (! Schema::hasTable($tableName)) {
continue;
}
Schema::table($tableName, function (Blueprint $table) use ($tableName): void {
foreach (['duration_seconds', 'ended_at', 'started_at'] as $column) {
if (Schema::hasColumn($tableName, $column)) {
$table->dropColumn($column);
}
}
});
}
}
};
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('helpdesk_ticket_time_logs')) {
return;
}
Schema::create('helpdesk_ticket_time_logs', function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->timestamp('started_at');
$table->timestamp('ended_at')->nullable();
$table->unsignedInteger('duration_seconds')->default(0);
$table->unsignedInteger('minutes')->default(0);
$table->text('description')->nullable();
$table->timestamps();
$table->index(['ticket_id', 'user_id', 'ended_at'], 'helpdesk_timer_active_idx');
$table->index(['ticket_id', 'started_at'], 'helpdesk_timer_ticket_started_idx');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('helpdesk_ticket_time_logs');
}
};
@@ -0,0 +1,41 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
if (Schema::hasTable('helpdesk_time_logs')) {
return;
}
Schema::create('helpdesk_time_logs', function (Blueprint $table): void {
$table->id();
$table->foreignId('ticket_id')->constrained('helpdesk_tickets')->cascadeOnDelete();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->unsignedInteger('minutes');
$table->text('description')->nullable();
$table->timestamp('logged_at')->useCurrent();
$table->timestamps();
$table->index(['ticket_id', 'logged_at']);
$table->index(['user_id', 'logged_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('helpdesk_time_logs');
}
};
@@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add the logged_at timestamp used by ticket time history and timer-created entries.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
return;
}
if (Schema::hasColumn('helpdesk_ticket_time_logs', 'logged_at')) {
return;
}
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
$table->timestamp('logged_at')->nullable()->after('ended_at')->index();
});
}
/**
* Remove the logged_at timestamp if this migration is rolled back.
*/
public function down(): void
{
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
return;
}
if (! Schema::hasColumn('helpdesk_ticket_time_logs', 'logged_at')) {
return;
}
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
$table->dropIndex(['logged_at']);
$table->dropColumn('logged_at');
});
}
};
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add seconds precision to helpdesk ticket timer logs.
*/
public function up(): void
{
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
return;
}
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_ticket_time_logs', 'seconds')) {
$table->unsignedInteger('seconds')->default(0)->after('minutes');
}
});
}
/**
* Remove seconds precision from helpdesk ticket timer logs.
*/
public function down(): void
{
if (! Schema::hasTable('helpdesk_ticket_time_logs')) {
return;
}
Schema::table('helpdesk_ticket_time_logs', function (Blueprint $table): void {
if (Schema::hasColumn('helpdesk_ticket_time_logs', 'seconds')) {
$table->dropColumn('seconds');
}
});
}
};
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Normalise legacy Flux/Tailwind colour names to the approved WMS palette.
*/
public function up(): void
{
foreach ($this->lookupTables() as $table) {
if (! Schema::hasTable($table) || ! Schema::hasColumn($table, 'color')) {
continue;
}
foreach ($this->colourMap() as $legacy => $approved) {
DB::table($table)->where('color', $legacy)->update(['color' => $approved]);
}
}
}
/**
* The migration is intentionally one-way because approved colours are the new baseline.
*/
public function down(): void
{
// No-op: do not reintroduce legacy colour aliases.
}
/**
* @return list<string>
*/
private function lookupTables(): array
{
return [
'helpdesk_statuses',
'helpdesk_priorities',
'helpdesk_categories',
'helpdesk_teams',
'helpdesk_projects',
'helpdesk_tags',
];
}
/**
* @return array<string, string>
*/
private function colourMap(): array
{
return [
'emerald' => 'green',
'lime' => 'green',
'rose' => 'red',
'yellow' => 'amber',
'orange' => 'amber',
'sky' => 'blue',
'cyan' => 'blue',
'violet' => 'purple',
'slate' => 'gray',
'zinc' => 'gray',
];
}
};
@@ -0,0 +1,64 @@
<?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 optional attachment metadata used by previews, source viewing and audit trails.
*/
public function up(): void
{
Schema::table('helpdesk_attachments', static function (Blueprint $table): void {
if (! Schema::hasColumn('helpdesk_attachments', 'extension')) {
$table->string('extension', 32)->nullable()->after('original_name')->index();
}
if (! Schema::hasColumn('helpdesk_attachments', 'category')) {
$table->string('category', 32)->nullable()->after('extension')->index();
}
if (! Schema::hasColumn('helpdesk_attachments', 'checksum_sha256')) {
$table->string('checksum_sha256', 64)->nullable()->after('size')->index();
}
if (! Schema::hasColumn('helpdesk_attachments', 'download_count')) {
$table->unsignedInteger('download_count')->default(0)->after('checksum_sha256');
}
if (! Schema::hasColumn('helpdesk_attachments', 'last_downloaded_at')) {
$table->timestamp('last_downloaded_at')->nullable()->after('download_count');
}
if (! Schema::hasColumn('helpdesk_attachments', 'deleted_at')) {
$table->timestamp('deleted_at')->nullable()->after('last_downloaded_at')->index();
}
if (! Schema::hasColumn('helpdesk_attachments', 'deleted_by')) {
$table->foreignId('deleted_by')->nullable()->after('deleted_at')->constrained('users')->nullOnDelete();
}
});
}
/**
* Remove attachment experience metadata.
*/
public function down(): void
{
Schema::table('helpdesk_attachments', static function (Blueprint $table): void {
if (Schema::hasColumn('helpdesk_attachments', 'deleted_by')) {
$table->dropConstrainedForeignId('deleted_by');
}
foreach (['deleted_at', 'last_downloaded_at', 'download_count', 'checksum_sha256', 'category', 'extension'] as $column) {
if (Schema::hasColumn('helpdesk_attachments', $column)) {
$table->dropColumn($column);
}
}
});
}
};