A CHECK constraint that documents a JSON shape

A JSON column accepts anything, which is the feature and is also how a column ends up with four different shapes in it.

ALTER TABLE orders ADD CONSTRAINT chk_meta_shape CHECK (
  JSON_SCHEMA_VALID(
    '{"type":"object",
      "required":["source","version"],
      "properties":{
        "source":{"type":"string"},
        "version":{"type":"integer","minimum":1}
      }}',
    meta
  )
);

The constraint is enforced on write, which means the backfill has to come first and the existing rows have to be made valid — ours had 41 with a missing version, all written by a script in 2020. What this buys is that the schema is in the database rather than in a comment, and a new writer cannot invent a fifth shape without being told.