perf(db): add missing indexes (appointment expiry, session dates, user status)

- appointments(status, expires_at): the per-minute expiry scheduler filtered on
  these with no covering index
- patient_sessions(created_at): dashboard revenue range scans
- users(status): admin user-list filter

PatientRecord(entity_type,entity_id) already covered by its unique constraint;
UserActiveContext.user_id is the PK — neither needed a new index.
This commit is contained in:
hamed
2026-06-28 17:13:44 +03:30
parent e1740462b5
commit 8b96753df6
4 changed files with 36 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260628134241 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add missing indexes: appointments(status, expires_at) for the expiry scheduler, patient_sessions(created_at) for dashboard revenue ranges, users(status) for admin filters.';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE INDEX idx_appointments_status_expires ON appointments (status, expires_at)');
$this->addSql('CREATE INDEX idx_patient_sessions_created_at ON patient_sessions (created_at)');
$this->addSql('CREATE INDEX idx_users_status ON users (status)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX idx_appointments_status_expires ON appointments');
$this->addSql('DROP INDEX idx_patient_sessions_created_at ON patient_sessions');
$this->addSql('DROP INDEX idx_users_status ON users');
}
}
+1
View File
@@ -12,6 +12,7 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Table(name: 'appointments')]
#[ORM\Index(columns: ['doctor_id', 'slot_start'], name: 'idx_appointments_doctor_slot')]
#[ORM\Index(columns: ['user_id', 'status'], name: 'idx_appointments_user_status')]
#[ORM\Index(columns: ['status', 'expires_at'], name: 'idx_appointments_status_expires')]
class Appointment
{
// Status machine: pending → confirmed → completed
+1
View File
@@ -11,6 +11,7 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'users')]
#[ORM\UniqueConstraint(name: 'uniq_mobile', columns: ['mobile_number'])]
#[ORM\Index(columns: ['status'], name: 'idx_users_status')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
+1
View File
@@ -11,6 +11,7 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: PatientSessionRepository::class)]
#[ORM\Table(name: 'patient_sessions')]
#[ORM\Index(columns: ['created_at'], name: 'idx_patient_sessions_created_at')]
class PatientSession
{
#[ORM\Id]