I am building a webapplication that uses hibernate and mysql and tomcat. Am constantly being asked for new features as the product evolves, and this often means that the data model needs to be changed.
What I am doing now is exporting all the critical data of the database to a flat file. Shutting down the database and the server, reconfiguring the database to match the new hibernate mappings and mysql tables and columns, importing the saved data programatically to fit the new data model, and then restarting the servers.
What else is recommended?
If you are interested in zero down time deployments then there are lots of ways to approach this. I found this blog post that outlines different strategies to achieve this.
The basic gist is that you do the database upgrade at a separate time to the main applications and ensure that the database has nullable columns and that the code can adjust to having columns mysteriously appear or disappear.
The author gives some strategies for doing this for different technologies – but then admits that it’s a bit fiddly to do this with hibernate:
It’s a great and interesting article and I recommend reading it all.
(Facebook and Yahoo don’t use Hibernate!)
To give the appearance of zero downtime from a users perspective, then it generally involves the use of application clusters protected by load balancers – so you can take each app out of policy and upgrade it without users trying to access it while it is restarting. You have to consider session stickyness, datasource consistency and all sorts of other stuff – but the main thing is that it isn’t magic.