Files
usher-manage-stack/database/migrations/2025_11_19_144027_create_issues_table.php
2025-11-20 23:21:05 +08:00

67 lines
2.8 KiB
PHP

<?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
{
Schema::create('issues', function (Blueprint $table) {
$table->id();
$table->string('issue_number')->unique()->comment('Auto-generated issue number (e.g., ISS-2025-001)');
$table->string('title');
$table->text('description')->nullable();
// Issue categorization
$table->enum('issue_type', ['work_item', 'project_task', 'maintenance', 'member_request'])
->default('work_item')
->comment('Type of issue');
$table->enum('status', ['new', 'assigned', 'in_progress', 'review', 'closed'])
->default('new')
->comment('Current workflow status');
$table->enum('priority', ['low', 'medium', 'high', 'urgent'])
->default('medium')
->comment('Priority level');
// User relationships
$table->foreignId('created_by_user_id')->constrained('users')->cascadeOnDelete()->comment('User who created the issue');
$table->foreignId('assigned_to_user_id')->nullable()->constrained('users')->nullOnDelete()->comment('User assigned to work on this');
$table->foreignId('reviewer_id')->nullable()->constrained('users')->nullOnDelete()->comment('User assigned to review');
// Related entities
$table->foreignId('member_id')->nullable()->constrained('members')->nullOnDelete()->comment('Related member (for member requests)');
$table->foreignId('parent_issue_id')->nullable()->constrained('issues')->nullOnDelete()->comment('Parent issue for sub-tasks');
// Dates and time tracking
$table->date('due_date')->nullable()->comment('Deadline for completion');
$table->timestamp('closed_at')->nullable()->comment('When issue was closed');
$table->decimal('estimated_hours', 8, 2)->nullable()->comment('Estimated time to complete');
$table->decimal('actual_hours', 8, 2)->default(0)->comment('Actual time spent (sum of time logs)');
$table->timestamps();
$table->softDeletes();
// Indexes for common queries
$table->index('issue_type');
$table->index('status');
$table->index('priority');
$table->index('assigned_to_user_id');
$table->index('created_by_user_id');
$table->index('due_date');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('issues');
}
};