<?php 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('clients',function(Blueprint $t){$t->id();$t->string('name');$t->string('company')->nullable();$t->string('email')->nullable();$t->string('phone')->nullable();$t->string('status')->default('active');$t->timestamps();});
Schema::create('projects',function(Blueprint $t){$t->id();$t->string('code')->unique();$t->string('name');$t->foreignId('client_id')->nullable()->constrained()->nullOnDelete();$t->foreignId('manager_user_id')->nullable()->constrained('users')->nullOnDelete();$t->foreignId('department_id')->nullable()->constrained()->nullOnDelete();$t->text('description')->nullable();$t->text('technology_stack')->nullable();$t->date('start_date')->nullable();$t->date('end_date')->nullable();$t->string('status')->default('active')->index();$t->string('priority')->default('medium');$t->string('health')->default('green');$t->decimal('budget_hours',10,2)->default(0);$t->string('confidentiality_level')->default('internal');$t->timestamps();});
Schema::create('project_members',function(Blueprint $t){$t->id();$t->foreignId('project_id')->constrained()->cascadeOnDelete();$t->foreignId('user_id')->constrained()->cascadeOnDelete();$t->string('role');$t->unsignedTinyInteger('allocation_percent')->default(100);$t->boolean('billable')->default(true);$t->date('start_date')->nullable();$t->date('end_date')->nullable();$t->text('responsibilities')->nullable();$t->string('access_level')->default('member');$t->timestamps();$t->index(['user_id','end_date']);});
Schema::create('tasks',function(Blueprint $t){$t->id();$t->foreignId('project_id')->constrained()->cascadeOnDelete();$t->string('title');$t->longText('description')->nullable();$t->foreignId('reporter_user_id')->nullable()->constrained('users')->nullOnDelete();$t->foreignId('primary_assignee_id')->nullable()->constrained('users')->nullOnDelete();$t->string('priority')->default('medium');$t->string('status')->default('backlog')->index();$t->unsignedInteger('estimate_minutes')->nullable();$t->date('start_date')->nullable();$t->date('due_date')->nullable()->index();$t->json('labels')->nullable();$t->longText('acceptance_criteria')->nullable();$t->text('blocked_reason')->nullable();$t->timestamp('completed_at')->nullable();$t->timestamps();});
Schema::create('task_assignees',function(Blueprint $t){$t->foreignId('task_id')->constrained()->cascadeOnDelete();$t->foreignId('user_id')->constrained()->cascadeOnDelete();$t->primary(['task_id','user_id']);});
Schema::create('task_status_histories',function(Blueprint $t){$t->id();$t->foreignId('task_id')->constrained()->cascadeOnDelete();$t->string('from_status')->nullable();$t->string('to_status');$t->foreignId('changed_by')->nullable()->constrained('users')->nullOnDelete();$t->timestamp('changed_at');$t->text('note')->nullable();});
Schema::create('work_logs',function(Blueprint $t){$t->id();$t->foreignId('user_id')->constrained()->cascadeOnDelete();$t->foreignId('project_id')->constrained()->cascadeOnDelete();$t->foreignId('task_id')->nullable()->constrained()->nullOnDelete();$t->date('work_date');$t->unsignedInteger('minutes');$t->text('description')->nullable();$t->timestamps();});
}public function down():void{Schema::dropIfExists('work_logs');Schema::dropIfExists('task_status_histories');Schema::dropIfExists('task_assignees');Schema::dropIfExists('tasks');Schema::dropIfExists('project_members');Schema::dropIfExists('projects');Schema::dropIfExists('clients');}};
