diff --git a/database/migrations/2026_07_18_100000_create_care_queue_engine_tables.php b/database/migrations/2026_07_18_100000_create_care_queue_engine_tables.php index d9584e7..b342fa5 100644 --- a/database/migrations/2026_07_18_100000_create_care_queue_engine_tables.php +++ b/database/migrations/2026_07_18_100000_create_care_queue_engine_tables.php @@ -8,69 +8,75 @@ return new class extends Migration { public function up(): void { - Schema::create('care_service_queues', function (Blueprint $table) { - $table->id(); - $table->uuid('uuid')->unique(); - $table->string('owner_ref', 64)->index(); - $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); - $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); - $table->string('context', 64); - $table->string('name'); - $table->string('prefix', 8); - $table->string('routing_mode', 32)->default('shared_pool'); - $table->string('external_key')->nullable()->index(); - $table->unsignedInteger('next_number')->default(1); - $table->boolean('is_active')->default(true); - $table->timestamps(); + if (! Schema::hasTable('care_service_queues')) { + Schema::create('care_service_queues', function (Blueprint $table) { + $table->id(); + $table->uuid('uuid')->unique(); + $table->string('owner_ref', 64)->index(); + $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); + $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); + $table->string('context', 64); + $table->string('name'); + $table->string('prefix', 8); + $table->string('routing_mode', 32)->default('shared_pool'); + $table->string('external_key')->nullable()->index(); + $table->unsignedInteger('next_number')->default(1); + $table->boolean('is_active')->default(true); + $table->timestamps(); - $table->unique(['organization_id', 'branch_id', 'context']); - }); + $table->unique(['organization_id', 'branch_id', 'context']); + }); + } - Schema::create('care_service_points', function (Blueprint $table) { - $table->id(); - $table->uuid('uuid')->unique(); - $table->string('owner_ref', 64)->index(); - $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); - $table->foreignId('service_queue_id')->constrained('care_service_queues')->cascadeOnDelete(); - $table->string('name'); - $table->string('destination')->nullable(); - $table->string('kind', 32)->default('default'); - $table->unsignedBigInteger('ref_id')->nullable(); - $table->string('staff_ref')->nullable(); - $table->string('staff_display_name')->nullable(); - $table->string('external_key')->nullable()->index(); - $table->boolean('is_active')->default(true); - $table->timestamps(); + if (! Schema::hasTable('care_service_points')) { + Schema::create('care_service_points', function (Blueprint $table) { + $table->id(); + $table->uuid('uuid')->unique(); + $table->string('owner_ref', 64)->index(); + $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); + $table->foreignId('service_queue_id')->constrained('care_service_queues')->cascadeOnDelete(); + $table->string('name'); + $table->string('destination')->nullable(); + $table->string('kind', 32)->default('default'); + $table->unsignedBigInteger('ref_id')->nullable(); + $table->string('staff_ref')->nullable(); + $table->string('staff_display_name')->nullable(); + $table->string('external_key')->nullable()->index(); + $table->boolean('is_active')->default(true); + $table->timestamps(); - $table->unique(['service_queue_id', 'external_key']); - }); + $table->unique(['service_queue_id', 'external_key']); + }); + } - Schema::create('care_queue_tickets', function (Blueprint $table) { - $table->id(); - $table->uuid('uuid')->unique(); - $table->string('owner_ref', 64)->index(); - $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); - $table->foreignId('service_queue_id')->constrained('care_service_queues')->cascadeOnDelete(); - $table->foreignId('service_point_id')->nullable()->constrained('care_service_points')->nullOnDelete(); - $table->string('ticket_number', 32); - $table->string('status', 32)->default('waiting')->index(); - $table->string('priority', 32)->default('walk_in'); - $table->string('source', 32)->default('api'); - $table->string('customer_name')->nullable(); - $table->string('customer_phone')->nullable(); - $table->string('care_entity', 32)->nullable(); - $table->string('care_entity_uuid', 36)->nullable()->index(); - $table->unsignedBigInteger('care_entity_id')->nullable(); - $table->unsignedBigInteger('visit_id')->nullable(); - $table->json('metadata')->nullable(); - $table->timestamp('called_at')->nullable(); - $table->timestamp('serving_at')->nullable(); - $table->timestamp('completed_at')->nullable(); - $table->timestamps(); + if (! Schema::hasTable('care_queue_tickets')) { + Schema::create('care_queue_tickets', function (Blueprint $table) { + $table->id(); + $table->uuid('uuid')->unique(); + $table->string('owner_ref', 64)->index(); + $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); + $table->foreignId('service_queue_id')->constrained('care_service_queues')->cascadeOnDelete(); + $table->foreignId('service_point_id')->nullable()->constrained('care_service_points')->nullOnDelete(); + $table->string('ticket_number', 32); + $table->string('status', 32)->default('waiting')->index(); + $table->string('priority', 32)->default('walk_in'); + $table->string('source', 32)->default('api'); + $table->string('customer_name')->nullable(); + $table->string('customer_phone')->nullable(); + $table->string('care_entity', 32)->nullable(); + $table->string('care_entity_uuid', 36)->nullable()->index(); + $table->unsignedBigInteger('care_entity_id')->nullable(); + $table->unsignedBigInteger('visit_id')->nullable(); + $table->json('metadata')->nullable(); + $table->timestamp('called_at')->nullable(); + $table->timestamp('serving_at')->nullable(); + $table->timestamp('completed_at')->nullable(); + $table->timestamps(); - $table->index(['service_queue_id', 'status']); - $table->index(['service_point_id', 'status']); - }); + $table->index(['service_queue_id', 'status']); + $table->index(['service_point_id', 'status']); + }); + } } public function down(): void diff --git a/database/migrations/2026_07_18_120000_create_care_specialty_clinical_records_table.php b/database/migrations/2026_07_18_120000_create_care_specialty_clinical_records_table.php index c5ce494..7d2c76c 100644 --- a/database/migrations/2026_07_18_120000_create_care_specialty_clinical_records_table.php +++ b/database/migrations/2026_07_18_120000_create_care_specialty_clinical_records_table.php @@ -8,6 +8,10 @@ return new class extends Migration { public function up(): void { + if (Schema::hasTable('care_specialty_clinical_records')) { + return; + } + Schema::create('care_specialty_clinical_records', function (Blueprint $table) { $table->id(); $table->uuid('uuid')->unique(); diff --git a/database/migrations/2026_07_18_140000_create_care_display_and_voice_tables.php b/database/migrations/2026_07_18_140000_create_care_display_and_voice_tables.php index df3b5b8..e56b746 100644 --- a/database/migrations/2026_07_18_140000_create_care_display_and_voice_tables.php +++ b/database/migrations/2026_07_18_140000_create_care_display_and_voice_tables.php @@ -8,40 +8,44 @@ return new class extends Migration { public function up(): void { - Schema::create('care_display_screens', function (Blueprint $table) { - $table->id(); - $table->uuid('uuid')->unique(); - $table->string('owner_ref')->index(); - $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); - $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); - $table->string('name'); - $table->string('layout')->default('standard'); - $table->string('access_token')->unique(); - $table->json('service_queue_ids')->nullable(); - $table->json('settings')->nullable(); - $table->boolean('is_active')->default(true); - $table->timestamp('last_seen_at')->nullable(); - $table->timestamps(); - $table->softDeletes(); - }); + if (! Schema::hasTable('care_display_screens')) { + Schema::create('care_display_screens', function (Blueprint $table) { + $table->id(); + $table->uuid('uuid')->unique(); + $table->string('owner_ref')->index(); + $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); + $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); + $table->string('name'); + $table->string('layout')->default('standard'); + $table->string('access_token')->unique(); + $table->json('service_queue_ids')->nullable(); + $table->json('settings')->nullable(); + $table->boolean('is_active')->default(true); + $table->timestamp('last_seen_at')->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } - Schema::create('care_voice_announcements', function (Blueprint $table) { - $table->id(); - $table->string('owner_ref')->index(); - $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); - $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); - $table->foreignId('ticket_id')->nullable()->constrained('care_queue_tickets')->nullOnDelete(); - $table->string('locale', 10)->default('en'); - $table->text('message'); - $table->string('voice')->default('female'); - $table->unsignedTinyInteger('volume')->default(80); - $table->unsignedTinyInteger('repeat_count')->default(1); - $table->string('status')->default('pending'); - $table->timestamp('played_at')->nullable(); - $table->timestamps(); + if (! Schema::hasTable('care_voice_announcements')) { + Schema::create('care_voice_announcements', function (Blueprint $table) { + $table->id(); + $table->string('owner_ref')->index(); + $table->foreignId('organization_id')->constrained('care_organizations')->cascadeOnDelete(); + $table->foreignId('branch_id')->constrained('care_branches')->cascadeOnDelete(); + $table->foreignId('ticket_id')->nullable()->constrained('care_queue_tickets')->nullOnDelete(); + $table->string('locale', 10)->default('en'); + $table->text('message'); + $table->string('voice')->default('female'); + $table->unsignedTinyInteger('volume')->default(80); + $table->unsignedTinyInteger('repeat_count')->default(1); + $table->string('status')->default('pending'); + $table->timestamp('played_at')->nullable(); + $table->timestamps(); - $table->index(['branch_id', 'status']); - }); + $table->index(['branch_id', 'status']); + }); + } } public function down(): void