How best to handle database version dependence (from $wp_db_version)

I sorted this out. It looks like the core team rolls out new versions of the database with their beta program. So, it’s plenty easy to get advance warning.

And, the database upgrades live in wp-admin/includes/upgrade.php.

There’s a sequence of functions in there named things like upgrade_500, upgrade_560, upgrade_590. They’re named for the WordPress version when they first become active: upgrade_560 is, for example, tied to version 5.6.

Working through those functions is like doing an archaeological dig. With each layer, you see what changed from the previous.

Database schema wise.

  • V4.2.0 database V 31351 handled the conversion to utfmb4 unicode, and introduced the prefix indexes like ALTER TABLE wp_usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191)).
  • V5.6, database V 49572 no longer has the column wp_posts.post_category.
  • V5.6, database V 49752 has the most recent upgrades for 5.8.x. No schema changes from V 49572. (Careful typing those version numbers, they’re almost the same.)
  • V5.9beta, database V 51917 has no schema changes from V 49572.