How to create a migration for the main Craft DB?
You're looking for the answer to a complicated problem. :)

What you're thinking of I would describe as "content migrations" or "content model syncing".

There is currently nothing in Craft out-of-the-box that will do what you're looking for, although we've got some ideas on how we'd like to approach the sharing/syncing of content between environments/installations in the long term.

If you need something before then, you'll have to write a plugin that rolls its own solution.