automatic undo for version control in mysql I'm not a mysql expert, but it seems like there is no obvious way to do that.
I'll explain what I want.
Let's say I'm doing a data migration which would update some rows in some table.

I'd like to be able to make a backup, execute migration script and get undo script automatically.

I don't see why this should be impossible, since rdbms stores all changes in a log already for transaction (mysql has --log-bin option for example) and they already know how to revert them (because they can rollback a transaction). So maybe it's possible to extract and use this data for the purpose of creating undo scripts for migrations?

EDIT.

Okay, so thanks to one of the answers I've found that mariadb actually partially support what I want already. This feature called flashbacks. It's actually doing what I've suggested - translating INSERTS into DELETE via binlog. So what I am missing is the upcoming support of flashbacks over DDL statements and making flashbacks only for one transaction.
I'd like to be able to make a backup, execute migration script and get undo script automatically. 


Why?

If the migration fails so badly that it's going to be abandoned, then restore your backup of the database. 
That's the only way to guarantee that you'll get back to the point you started from. 

I don't know of any way to create an "undo" script but, even if you could, there's no guarantee that it would work, potentially failing part way through its "recovery" and leaving you in an even worse position, somewhere between the last known Good State and the point where the migration failed but you won't be exactly sure where.  From then on, you're clutching at straws to try and clean up the mess. 

Far better ( / easier / more reliable) to toss the "corrupted" database in the bin and restore it from the backup.