diff --git a/database/migrations/2026_07_18_160000_create_care_dentistry_tables.php b/database/migrations/2026_07_18_160000_create_care_dentistry_tables.php index a76ae2d..4e56186 100644 --- a/database/migrations/2026_07_18_160000_create_care_dentistry_tables.php +++ b/database/migrations/2026_07_18_160000_create_care_dentistry_tables.php @@ -56,7 +56,7 @@ return new class extends Migration $table->timestamp('recorded_at')->nullable(); $table->timestamps(); - $table->index(['dental_chart_id', 'recorded_at']); + $table->index(['dental_chart_id', 'recorded_at'], 'care_den_chart_events_chart_at_idx'); $table->index(['visit_id']); }); } @@ -78,7 +78,18 @@ return new class extends Migration $table->timestamps(); $table->softDeletes(); - $table->index(['organization_id', 'patient_id', 'status']); + $table->index( + ['organization_id', 'patient_id', 'status'], + 'care_den_plans_org_pt_status_idx', + ); + }); + } elseif (! $this->hasIndex('care_dental_treatment_plans', 'care_den_plans_org_pt_status_idx')) { + // Partial deploy: table created before long auto index name failed (MySQL 64-char limit). + Schema::table('care_dental_treatment_plans', function (Blueprint $table) { + $table->index( + ['organization_id', 'patient_id', 'status'], + 'care_den_plans_org_pt_status_idx', + ); }); } @@ -98,7 +109,7 @@ return new class extends Migration $table->text('notes')->nullable(); $table->timestamps(); - $table->index(['treatment_plan_id', 'status']); + $table->index(['treatment_plan_id', 'status'], 'care_den_plan_items_plan_status_idx'); }); } @@ -124,8 +135,8 @@ return new class extends Migration $table->timestamp('performed_at')->nullable(); $table->timestamps(); - $table->index(['visit_id', 'status']); - $table->index(['organization_id', 'procedure_code']); + $table->index(['visit_id', 'status'], 'care_den_proc_visit_status_idx'); + $table->index(['organization_id', 'procedure_code'], 'care_den_proc_org_code_idx'); }); } @@ -145,8 +156,8 @@ return new class extends Migration $table->timestamp('captured_at')->nullable(); $table->timestamps(); - $table->index(['visit_id', 'modality']); - $table->index(['patient_id', 'captured_at']); + $table->index(['visit_id', 'modality'], 'care_den_images_visit_mod_idx'); + $table->index(['patient_id', 'captured_at'], 'care_den_images_patient_cap_idx'); }); } @@ -171,6 +182,18 @@ return new class extends Migration } } + protected function hasIndex(string $table, string $indexName): bool + { + $connection = Schema::getConnection(); + $database = $connection->getDatabaseName(); + $row = $connection->selectOne( + 'select 1 as ok from information_schema.statistics where table_schema = ? and table_name = ? and index_name = ? limit 1', + [$database, $table, $indexName], + ); + + return $row !== null; + } + public function down(): void { Schema::dropIfExists('care_dental_visit_notes');