convert_encrypted_to_plaintext
Convert legacy encrypted cache columns to plaintext in place.
The cache no longer encrypts columns at rest: the Migrating* decorators write
plaintext and decrypt a legacy enc:v1: value on read. This migration rewrites
those legacy values to plaintext eagerly and deterministically — rather than
waiting for each row to be re-written by a future pipeline run — so a clinic pod
that already holds real (encrypted) data converges at startup.
It works on the raw column TEXT via _decrypt_text, independent of the ORM
decorators, and introspects which columns actually exist so it is safe across
cache tables at any registered version. It only touches values still carrying
the enc:v1: prefix, so it is idempotent, and needs the encryption key only
if such values are present (an already-plaintext cache is a no-op).
A value that cannot be decrypted — a corrupt row, an unavailable/wrong key, or a plaintext value that merely looks encrypted — is left as-is and skipped, never fatal. This keeps it no worse than the previous decrypt-on-read behaviour (where only that row's read would fail): the migration must not turn one bad value into a failure that blocks the cache from opening. Skipped values stay readable on demand and converge to plaintext on their next pipeline write.
Module
Functions
apply
def apply(cache: CacheProtocol) ‑> int:Rewrite every legacy enc:v1: value across the cache to plaintext.
Arguments
cache: The cache backend (opened with the pod key bound, so decryption can resolve the key if any encrypted rows are present).
Returns The number of values rewritten.
Global variables
NAME- Identifier recorded in the migration marker once this has run.