fixed events+tasks system migration
This commit is contained in:
@@ -9,7 +9,7 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
// Events table
|
// Events table
|
||||||
if (!Schema::hasTable('events')) {
|
if (! Schema::hasTable('events')) {
|
||||||
Schema::create('events', function (Blueprint $table) {
|
Schema::create('events', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('tenant_id')->constrained()->onDelete('cascade');
|
$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');
|
$table->foreign('event_type_id')->references('id')->on('event_types')->onDelete('restrict');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (!Schema::hasColumn('events', 'status')) {
|
if (! Schema::hasColumn('events', 'status')) {
|
||||||
Schema::table('events', function (Blueprint $table) {
|
Schema::table('events', function (Blueprint $table) {
|
||||||
$table->enum('status', ['draft', 'published', 'archived'])->default('draft')->after('is_active');
|
$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
|
// Task Collections
|
||||||
if (!Schema::hasTable('task_collections')) {
|
if (! Schema::hasTable('task_collections')) {
|
||||||
Schema::create('task_collections', function (Blueprint $table) {
|
Schema::create('task_collections', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('tenant_id')->nullable()->constrained()->nullOnDelete();
|
$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
|
// Task Collection - Task Pivot
|
||||||
if (!Schema::hasTable('task_collection_task')) {
|
if (! Schema::hasTable('task_collection_task')) {
|
||||||
Schema::create('task_collection_task', function (Blueprint $table) {
|
Schema::create('task_collection_task', function (Blueprint $table) {
|
||||||
$table->foreignId('task_collection_id')->constrained()->onDelete('cascade');
|
$table->foreignId('task_collection_id')->constrained()->onDelete('cascade');
|
||||||
$table->foreignId('task_id')->constrained()->onDelete('cascade');
|
$table->foreignId('task_id')->constrained()->onDelete('cascade');
|
||||||
@@ -99,7 +99,7 @@ return new class extends Migration
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event - Task Collection Pivot
|
// Event - Task Collection Pivot
|
||||||
if (!Schema::hasTable('event_task_collection')) {
|
if (! Schema::hasTable('event_task_collection')) {
|
||||||
Schema::create('event_task_collection', function (Blueprint $table) {
|
Schema::create('event_task_collection', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('event_id')->constrained('events')->onDelete('cascade');
|
$table->foreignId('event_id')->constrained('events')->onDelete('cascade');
|
||||||
@@ -110,7 +110,7 @@ return new class extends Migration
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event - Task Pivot
|
// Event - Task Pivot
|
||||||
if (!Schema::hasTable('event_task')) {
|
if (! Schema::hasTable('event_task')) {
|
||||||
Schema::create('event_task', function (Blueprint $table) {
|
Schema::create('event_task', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('event_id')->constrained()->onDelete('cascade');
|
$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)
|
// 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) {
|
Schema::table('tasks', function (Blueprint $table) {
|
||||||
$table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id');
|
$table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id');
|
||||||
$table->index('tenant_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) {
|
Schema::table('task_collections', function (Blueprint $table) {
|
||||||
$table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id');
|
$table->foreignId('tenant_id')->constrained('tenants')->onDelete('cascade')->after('id');
|
||||||
$table->index('tenant_id');
|
$table->index('tenant_id');
|
||||||
|
|||||||
Reference in New Issue
Block a user