create_patient_eligibility_trial_index
Add the eligible_trials filter 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 (declared
on the patient_eligibility ORM's __table_args__) never gains the index on
open. This migration creates it in place, so an existing pod gets the same
index-driven eligible_trials filter that a fresh cache has from its ORM.
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 — so it lives here
with the other one-time cache migrations. The DDL is taken from the ORM Index
object rather than re-spelled, so the two cannot drift.
Idempotent: a no-op once the index exists (which includes every fresh cache,
where create_all already built it). Building the index scans the whole
patient_eligibility table, so the first run on a large existing cache costs a
few seconds; the migration marker then stops it re-running.
Module
Functions
apply
def apply(cache: CacheProtocol) ‑> int:Create the trial-filter index if it is missing.
Arguments
cache: The cache backend.
Returns 1 if the index was created, 0 if it already existed.
Global variables
NAME- Identifier recorded in the migration marker once this has run.