Implement ticket types priorities and custom fields

This commit is contained in:
2026-03-25 01:28:25 +01:00
parent 3f9b83ec16
commit 35aacff318
32 changed files with 1832 additions and 1 deletions
@@ -0,0 +1,28 @@
<?php
namespace Database\Factories;
use App\Models\Project;
use App\Models\TicketFieldDefinition;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TicketFieldDefinition>
*/
class TicketFieldDefinitionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'field_type' => fake()->randomElement(TicketFieldDefinition::FIELD_TYPES),
'label' => fake()->unique()->words(2, true),
'position' => 1,
'project_id' => Project::factory(),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use App\Models\Project;
use App\Models\TicketPriority;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TicketPriority>
*/
class TicketPriorityFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->randomElement(['Low', 'Medium', 'High', 'Urgent']),
'position' => 1,
'project_id' => Project::factory(),
];
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace Database\Factories;
use App\Models\Project;
use App\Models\TicketType;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TicketType>
*/
class TicketTypeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'is_builtin' => false,
'name' => fake()->unique()->jobTitle(),
'position' => 1,
'project_id' => Project::factory(),
'system_key' => null,
];
}
}
@@ -0,0 +1,35 @@
<?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('ticket_types', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->string('system_key')->nullable();
$table->boolean('is_builtin')->default(false);
$table->unsignedInteger('position');
$table->timestamps();
$table->unique(['project_id', 'position']);
$table->unique(['project_id', 'system_key']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ticket_types');
}
};
@@ -0,0 +1,32 @@
<?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('ticket_priorities', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->unsignedInteger('position');
$table->timestamps();
$table->unique(['project_id', 'position']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ticket_priorities');
}
};
@@ -0,0 +1,33 @@
<?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('ticket_field_definitions', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained()->cascadeOnDelete();
$table->string('label');
$table->string('field_type');
$table->unsignedInteger('position');
$table->timestamps();
$table->unique(['project_id', 'position']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ticket_field_definitions');
}
};
+1
View File
@@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder
UserSeeder::class,
ProjectSeeder::class,
BoardColumnSeeder::class,
ProjectTicketMetadataSeeder::class,
TeamSeeder::class,
ProjectAccessSeeder::class,
]);
@@ -0,0 +1,55 @@
<?php
namespace Database\Seeders;
use App\Actions\ProjectTicketMetadata\InitializeProjectTicketMetadata;
use App\Models\Project;
use App\Models\TicketFieldDefinition;
use App\Models\TicketPriority;
use App\Models\TicketType;
use Illuminate\Database\Seeder;
class ProjectTicketMetadataSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$initializeProjectTicketMetadata = app(InitializeProjectTicketMetadata::class);
Project::query()
->orderBy('id')
->get()
->each(function (Project $project) use ($initializeProjectTicketMetadata): void {
$initializeProjectTicketMetadata->handle($project);
TicketType::factory()
->for($project)
->create([
'name' => 'Bug',
'position' => 3,
'system_key' => null,
]);
TicketPriority::factory()
->count(3)
->sequence(
['name' => 'Low', 'position' => 1],
['name' => 'Medium', 'position' => 2],
['name' => 'High', 'position' => 3],
)
->for($project)
->create();
TicketFieldDefinition::factory()
->count(2)
->sequence(
['label' => 'Assignee', 'field_type' => 'user', 'position' => 1],
['label' => 'Story Points', 'field_type' => 'number', 'position' => 2],
)
->for($project)
->create();
});
}
}