It was noticed by @Nikerabbit when updating translatewiki, that there is definitely some skew between the active schema for the wiki, and tables.sql - for example, it seems it already had a PK on log_search, which was added/removed in 1.16 cycle, and then re-added in 1.30... But the unique index wasn't removed again due to the patch doing both in one.
I know the DBA's have some ways of doing this, to find discrepancies in WMF production, but we should have something more "general purpose" in mediawiki, that can be used to find these differences... And if people report them back to us, we can look at implementing patches (that can often have been missed for one reason or another) to bring their wikis back into sync.
Usually, it's less obvious changes, index names, existence etc, rather than completely missing columns... But sometimes it can be differing data types
A quick google finds things like https://github.com/DBDiff/DBDiff and https://github.com/camcima/php-mysql-diff which both can be installed via composer, so would happily fit in our require-dev category. I'm not sure how well they fit our purpose, but not reinventing the wheel as much as possible should be a priority in this task. Both seem reasonably well maintained (active at least), so upstream bugs shouldn't be an issue if we run into problems.
I've no idea how exactly this will look... But just dumping thoughts here in the meantime