add migrations with factory and seeders
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Has been cancelled Details

This commit is contained in:
aslan 2024-05-23 14:48:29 +03:00
parent 501aa384c8
commit 72bc5ec8ae
22 changed files with 181 additions and 183 deletions

View File

@ -8,4 +8,10 @@ use Illuminate\Database\Eloquent\Model;
class Department extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'created_by_id',
];
}

View File

@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model;
class Label extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'department_id',
'created_by_id',
];
}

View File

@ -10,7 +10,6 @@ class LabelFactory extends Factory
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
];
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProjectFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->name(),
'description' => fake()->text(),
];
}
}

View File

@ -12,6 +12,7 @@ class TaskFactory extends Factory
'name' => fake()->name(),
'file' => fake()->name(),
'description' => fake()->text(),
'project_id' => 1,
'parent_id' => 0,
'status_id' => 1,
'department_id' => 1,

View File

@ -10,6 +10,7 @@ class TaskStatusesFactory extends Factory
{
return [
'name' => fake()->name(),
'project_id' => 1,
];
}
}

View File

@ -16,6 +16,7 @@ class UserFactory extends Factory
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'department_id' => 1,
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];

View File

@ -12,6 +12,7 @@ return new class extends Migration
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->foreignId('department_id')->constrained('departments');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();

View File

@ -0,0 +1,30 @@
<?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('projects', function (Blueprint $table) {
$table->id();
$table->string('name', 255);
$table->text('description');
$table->foreignId('department_id')->constrained('departments');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('projects');
}
};

View File

@ -11,6 +11,7 @@ return new class extends Migration
Schema::create('task_statuses', function (Blueprint $table) {
$table->id();
$table->string('name', 255);
$table->foreignId('project_id')->constrained('projects');
$table->timestamps();
});
}

View File

@ -11,7 +11,6 @@ return new class extends Migration
Schema::create('labels', function (Blueprint $table) {
$table->id();
$table->string('name', 255);
$table->string('description')->nullable();
$table->timestamps();
});
}

View File

@ -13,8 +13,8 @@ return new class extends Migration
$table->string('name', 255);
$table->bigInteger('parent_id');
$table->text('description')->nullable();
$table->foreignId('project_id')->constrained('projects');
$table->foreignId('status_id')->constrained('task_statuses');
$table->foreignId('department_id')->constrained('departments');
$table->foreignId('created_by_id')->constrained('users');
$table->timestamps();
});

View File

@ -8,8 +8,8 @@ return new class extends Migration
{
public function up(): void
{
Schema::create('task_user', function (Blueprint $table) {
$table->foreignId('task_id')->constrained('tasks');
Schema::create('project_user', function (Blueprint $table) {
$table->foreignId('project_id')->constrained('projects');
$table->foreignId('user_id')->constrained('users');
$table->timestamps();
});
@ -17,6 +17,6 @@ return new class extends Migration
public function down(): void
{
Schema::dropIfExists('task_user');
Schema::dropIfExists('project_user');
}
};

View File

@ -11,22 +11,27 @@ class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
DepartmentSeeder::class,
]);
User::factory(20)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
'department_id' => 1,
'password' => Hash::make('password'),
]);
$this->call([
DepartmentSeeder::class,
ProjectSeeder::class,
LabelSeeder::class,
TaskStatusSeeder::class,
TaskSeeder::class,
NoteSeeder::class,
LabelTaskSeeder::class,
TaskUserSeeder::class,
ProjectUserSeeder::class,
]);
}
}

View File

@ -12,6 +12,10 @@ class DepartmentSeeder extends Seeder
public function run(): void
{
DB::table('departments')->insert([
[
'name' => 'без отдела',
'created_at' => Carbon::now(),
],
[
'name' => 'отдел Разработки',
'created_at' => Carbon::now(),

View File

@ -14,22 +14,18 @@ class LabelSeeder extends Seeder
DB::table('labels')->insert([
[
'name' => 'ошибка',
'description' => 'Какая-то ошибка в коде или проблема с функциональностью',
'created_at' => Carbon::now(),
],
[
'name' => 'документация',
'description' => 'Задача которая касается документации',
'created_at' => Carbon::now(),
],
[
'name' => 'дубликат',
'description' => 'Повтор другой задачи',
'created_at' => Carbon::now(),
],
[
'name' => 'доработка',
'description' => 'Новая фича, которую нужно запилить',
'created_at' => Carbon::now(),
],
]);

View File

@ -0,0 +1,35 @@
<?php
namespace Database\Seeders;
use Carbon\Carbon;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ProjectSeeder extends Seeder
{
public function run(): void
{
DB::table('projects')->insert([
[
'name' => 'Сайт для Абитуриентов',
'description' => 'разработка Сайт для Абитуриентов',
'department_id' => 1,
'created_at' => Carbon::now(),
],
[
'name' => 'Личный кабинет студента',
'description' => 'разработка Личный кабинет студента',
'department_id' => 1,
'created_at' => Carbon::now(),
],
[
'name' => 'Личный кабинет преподователя',
'description' => 'разработка Личный кабинет преподователя',
'department_id' => 1,
'created_at' => Carbon::now(),
],
]);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ProjectUserSeeder extends Seeder
{
public function run(): void
{
DB::table('project_user')->insert([
[
'project_id' => 1,
'user_id' => 2,
],
[
'project_id' => 1,
'user_id' => 4,
],
[
'project_id' => 2,
'user_id' => 1,
],
[
'project_id' => 2,
'user_id' => 3,
],
[
'project_id' => 2,
'user_id' => 4,
],
[
'project_id' => 3,
'user_id' => 1,
],
[
'project_id' => 3,
'user_id' => 2,
],
[
'project_id' => 3,
'user_id' => 3,
],
]);
}
}

View File

@ -18,8 +18,8 @@ class TaskSeeder extends Seeder
'description' => 'Я тут ошибку нашёл, надо бы её исправить и так далее и так далее',
'created_by_id' => 1,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 0,
'department_id' => 1,
],
[
'status_id' => 2,
@ -27,8 +27,8 @@ class TaskSeeder extends Seeder
'description' => 'Вёрстка поехала в далёкие края. Нужно удалить бутстрап!',
'created_by_id' => 2,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 0,
'department_id' => 1,
],
[
'status_id' => 3,
@ -36,8 +36,8 @@ class TaskSeeder extends Seeder
'description' => 'Выпилить всё легаси, которое найдёшь',
'created_by_id' => 2,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 0,
'department_id' => 1,
],
[
'status_id' => 4,
@ -45,8 +45,8 @@ class TaskSeeder extends Seeder
'description' => 'За одно добавить тестовых данных',
'created_by_id' => 1,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 0,
'department_id' => 1,
],
[
'status_id' => 1,
@ -54,8 +54,8 @@ class TaskSeeder extends Seeder
'description' => 'Кажется она не того цвета',
'created_by_id' => 3,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 2,
@ -63,8 +63,8 @@ class TaskSeeder extends Seeder
'description' => 'Не ищет то, что мне хочется',
'created_by_id' => 5,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 3,
@ -72,8 +72,8 @@ class TaskSeeder extends Seeder
'description' => 'Они такие мягкие и пушистые',
'created_by_id' => 7,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 4,
@ -81,8 +81,8 @@ class TaskSeeder extends Seeder
'description' => '',
'created_by_id' => 9,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 1,
@ -90,8 +90,8 @@ class TaskSeeder extends Seeder
'description' => 'Кому-то же они нужны?',
'created_by_id' => 11,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 2,
@ -99,8 +99,8 @@ class TaskSeeder extends Seeder
'description' => 'Этот сериал никому не нравится! :)',
'created_by_id' => 13,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 4,
@ -108,8 +108,8 @@ class TaskSeeder extends Seeder
'description' => 'Передать Олегу, чтобы больше не ронял прод',
'created_by_id' => 2,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 1,
@ -117,8 +117,8 @@ class TaskSeeder extends Seeder
'description' => 'Андрей, это задача для тебя',
'created_by_id' => 4,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 2,
@ -126,8 +126,8 @@ class TaskSeeder extends Seeder
'description' => 'Не забыть потестировать',
'created_by_id' => 6,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 3,
@ -135,8 +135,8 @@ class TaskSeeder extends Seeder
'description' => 'Кризис это не время, чтобы молчать!',
'created_by_id' => 8,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 4,
@ -144,8 +144,8 @@ class TaskSeeder extends Seeder
'description' => 'Только не по моему',
'created_by_id' => 10,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
[
'status_id' => 1,
@ -153,8 +153,8 @@ class TaskSeeder extends Seeder
'description' => '',
'created_by_id' => 13,
'created_at' => Carbon::now(),
'project_id' => 1,
'parent_id' => 1,
'department_id' => 1,
],
]);
}

View File

@ -14,18 +14,22 @@ class TaskStatusSeeder extends Seeder
DB::table('task_statuses')->insert([
[
'name' => 'Создан',
'project_id' => 1,
'created_at' => Carbon::now(),
],
[
'name' => 'В работе',
'project_id' => 1,
'created_at' => Carbon::now(),
],
[
'name' => 'На проверке',
'project_id' => 1,
'created_at' => Carbon::now(),
],
[
'name' => 'Выполнен',
'project_id' => 1,
'created_at' => Carbon::now(),
],
]);

View File

@ -1,155 +0,0 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class TaskUserSeeder extends Seeder
{
public function run(): void
{
DB::table('task_user')->insert([
[
'task_id' => 1,
'user_id' => 2,
],
[
'task_id' => 1,
'user_id' => 4,
],
[
'task_id' => 2,
'user_id' => 1,
],
[
'task_id' => 2,
'user_id' => 3,
],
[
'task_id' => 2,
'user_id' => 4,
],
[
'task_id' => 3,
'user_id' => 1,
],
[
'task_id' => 3,
'user_id' => 2,
],
[
'task_id' => 3,
'user_id' => 3,
],
[
'task_id' => 4,
'user_id' => 2,
],
[
'task_id' => 4,
'user_id' => 4,
],
[
'task_id' => 5,
'user_id' => 3,
],
[
'task_id' => 6,
'user_id' => 1,
],
[
'task_id' => 6,
'user_id' => 4,
],
[
'task_id' => 7,
'user_id' => 1,
],
[
'task_id' => 8,
'user_id' => 1,
],
[
'task_id' => 8,
'user_id' => 2,
],
[
'task_id' => 8,
'user_id' => 3,
],
[
'task_id' => 8,
'user_id' => 4,
],
[
'task_id' => 9,
'user_id' => 1,
],
[
'task_id' => 9,
'user_id' => 2,
],
[
'task_id' => 9,
'user_id' => 4,
],
[
'task_id' => 10,
'user_id' => 2,
],
[
'task_id' => 10,
'user_id' => 3,
],
[
'task_id' => 10,
'user_id' => 4,
],
[
'task_id' => 11,
'user_id' => 2,
],
[
'task_id' => 11,
'user_id' => 4,
],
[
'task_id' => 12,
'user_id' => 1,
],
[
'task_id' => 13,
'user_id' => 4,
],
[
'task_id' => 14,
'user_id' => 2,
],
[
'task_id' => 15,
'user_id' => 1,
],
[
'task_id' => 15,
'user_id' => 2,
],
[
'task_id' => 15,
'user_id' => 3,
],
[
'task_id' => 16,
'user_id' => 1,
],
[
'task_id' => 16,
'user_id' => 2,
],
[
'task_id' => 16,
'user_id' => 3,
],
]);
}
}