From d2fa5f943e186716b0ec3a8506445284d3ebd23d Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Sat, 15 Nov 2025 21:18:39 +0100 Subject: [PATCH] fixed events+tasks system migration --- .../2025_09_01_000300_create_events_tasks.php | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/database/migrations/2025_09_01_000300_create_events_tasks.php b/database/migrations/2025_09_01_000300_create_events_tasks.php index dffe503..0e2c3dc 100644 --- a/database/migrations/2025_09_01_000300_create_events_tasks.php +++ b/database/migrations/2025_09_01_000300_create_events_tasks.php @@ -9,7 +9,7 @@ return new class extends Migration public function up(): void { // Events table - if (!Schema::hasTable('events')) { + if (! Schema::hasTable('events')) { Schema::create('events', function (Blueprint $table) { $table->id(); $table->foreignId('tenant_id')->constrained()->onDelete('cascade'); @@ -32,48 +32,15 @@ return new class extends Migration $table->foreign('event_type_id')->references('id')->on('event_types')->onDelete('restrict'); }); } else { - if (!Schema::hasColumn('events', 'status')) { + if (! Schema::hasColumn('events', 'status')) { Schema::table('events', function (Blueprint $table) { $table->enum('status', ['draft', 'published', 'archived'])->default('draft')->after('is_active'); }); } } - // Tasks table - if (!Schema::hasTable('tasks')) { - Schema::create('tasks', function (Blueprint $table) { - $table->id(); - $table->foreignId('tenant_id')->nullable()->constrained()->nullOnDelete(); - $table->string('slug')->nullable()->unique(); - $table->unsignedBigInteger('emotion_id')->nullable(); - $table->unsignedBigInteger('event_type_id')->nullable(); - $table->json('title'); - $table->json('description')->nullable(); - $table->json('example_text')->nullable(); - $table->dateTime('due_date')->nullable(); - $table->boolean('is_completed')->default(false); - $table->enum('priority', ['low', 'medium', 'high', 'urgent'])->default('medium'); - $table->unsignedBigInteger('collection_id')->nullable(); - $table->enum('difficulty', ['easy','medium','hard'])->default('easy'); - $table->integer('sort_order')->default(0); - $table->boolean('is_active')->default(true); - $table->softDeletes(); // From add_soft_deletes_to_tasks_table - $table->timestamps(); - $table->index(['tenant_id', 'is_completed', 'priority']); - $table->foreign('emotion_id')->references('id')->on('emotions')->onDelete('set null'); - $table->foreign('event_type_id')->references('id')->on('event_types')->onDelete('set null'); - $table->foreign('collection_id')->references('id')->on('task_collections')->onDelete('set null'); - }); - } else { - if (!Schema::hasColumn('tasks', 'deleted_at')) { - Schema::table('tasks', function (Blueprint $table) { - $table->softDeletes(); - }); - } - } - // Task Collections - if (!Schema::hasTable('task_collections')) { + if (! Schema::hasTable('task_collections')) { Schema::create('task_collections', function (Blueprint $table) { $table->id(); $table->foreignId('tenant_id')->nullable()->constrained()->nullOnDelete(); @@ -88,8 +55,41 @@ return new class extends Migration }); } + // Tasks table + if (! Schema::hasTable('tasks')) { + Schema::create('tasks', function (Blueprint $table) { + $table->id(); + $table->foreignId('tenant_id')->nullable()->constrained()->nullOnDelete(); + $table->string('slug')->nullable()->unique(); + $table->unsignedBigInteger('emotion_id')->nullable(); + $table->unsignedBigInteger('event_type_id')->nullable(); + $table->json('title'); + $table->json('description')->nullable(); + $table->json('example_text')->nullable(); + $table->dateTime('due_date')->nullable(); + $table->boolean('is_completed')->default(false); + $table->enum('priority', ['low', 'medium', 'high', 'urgent'])->default('medium'); + $table->unsignedBigInteger('collection_id')->nullable(); + $table->enum('difficulty', ['easy', 'medium', 'hard'])->default('easy'); + $table->integer('sort_order')->default(0); + $table->boolean('is_active')->default(true); + $table->softDeletes(); // From add_soft_deletes_to_tasks_table + $table->timestamps(); + $table->index(['tenant_id', 'is_completed', 'priority']); + $table->foreign('emotion_id')->references('id')->on('emotions')->onDelete('set null'); + $table->foreign('event_type_id')->references('id')->on('event_types')->onDelete('set null'); + $table->foreign('collection_id')->references('id')->on('task_collections')->onDelete('set null'); + }); + } else { + if (! Schema::hasColumn('tasks', 'deleted_at')) { + Schema::table('tasks', function (Blueprint $table) { + $table->softDeletes(); + }); + } + } + // Task Collection - Task Pivot - if (!Schema::hasTable('task_collection_task')) { + if (! Schema::hasTable('task_collection_task')) { Schema::create('task_collection_task', function (Blueprint $table) { $table->foreignId('task_collection_id')->constrained()->onDelete('cascade'); $table->foreignId('task_id')->constrained()->onDelete('cascade'); @@ -99,7 +99,7 @@ return new class extends Migration } // Event - Task Collection Pivot - if (!Schema::hasTable('event_task_collection')) { + if (! Schema::hasTable('event_task_collection')) { Schema::create('event_task_collection', function (Blueprint $table) { $table->id(); $table->foreignId('event_id')->constrained('events')->onDelete('cascade'); @@ -110,7 +110,7 @@ return new class extends Migration } // Event - Task Pivot - if (!Schema::hasTable('event_task')) { + if (! Schema::hasTable('event_task')) { Schema::create('event_task', function (Blueprint $table) { $table->id(); $table->foreignId('event_id')->constrained()->onDelete('cascade'); @@ -121,13 +121,13 @@ return new class extends Migration } // Add tenant_id to tasks and collections if missing (from add_tenant_id_to_tasks_and_collections) - if (Schema::hasTable('tasks') && !Schema::hasColumn('tasks', 'tenant_id')) { + if (Schema::hasTable('tasks') && ! Schema::hasColumn('tasks', 'tenant_id')) { Schema::table('tasks', function (Blueprint $table) { $table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id'); $table->index('tenant_id'); }); } - if (Schema::hasTable('task_collections') && !Schema::hasColumn('task_collections', 'tenant_id')) { + if (Schema::hasTable('task_collections') && ! Schema::hasColumn('task_collections', 'tenant_id')) { Schema::table('task_collections', function (Blueprint $table) { $table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id'); $table->index('tenant_id');