Skip to main content

create_patient_eligibility_trial_score_index

Add the trial-patient ordering index to caches created before it existed.

metadata.create_all only builds a table's indexes at the moment it creates the table, so a cache predating ix_patient_eligibility_trial_status_score (declared on the v2 patient_eligibility ORM's __table_args__) never gains the index on open. This migration creates it in place, so an existing pod serves the single-trial patient listing's score ordering off the index like a fresh cache.

Unlike a per-type schema migration this is not tied to a version bump — the record shape is unchanged, only a secondary index is added. The DDL is taken from the ORM Index object rather than re-spelled, so the two cannot drift.

A cache is created at v1 and hopped to v2, and the hop adds the column but not this index, so every cache gets it from here rather than from create_all.

Registered in cache.migrations._RECONCILED, re-checked on every open rather than marker-gated: the index needs the v2 column, which a table still at v1 lacks, and a marker would stop the build ever being retried once that table is upgraded.

Idempotent: a no-op once the index exists, and a no-op while the table has no eligibility_score column. Building the index scans the whole patient_eligibility table, so the first run on a large existing cache costs a few seconds.

Module​

Functions​

apply​

def apply(cache: CacheProtocol) ‑> int:

Create the trial-patient ordering index if it is missing.

Arguments

  • cache: The cache backend.

Returns 1 if the index was created, 0 if it already existed, the ORM no longer declares it, or the table is not yet at v2.