[1.7.x] Fixed #22350 -- Consistently serialize bytes and text in migrations.

Thanks to @treyhunner and Loïc for their suggestions and review.

Backport of 72d3889db4 from master
[1.7.x] Fixed #22398 -- Added detail about callable in KEY_FUNCTION docs

Backport of 8da86fd19b from master