Odoo Database Upgrade FAQ

8. Can I script my database upgrade?

Yes, you can use the Upgrade API described here:
https://www.odoo.com/documentation/9.0/reference/upgrade_api.html

You can have more information (and a link to a sample script) in question 7