| Author |
Database Schema Updates
|
Chuck Syp
Greenhorn
Joined: Feb 05, 2010
Posts: 5
|
|
I have a JSF application that uses hibernate with a MySql database, and I was wondering what most people do to handle database installation/database changes between versions of an application. I want my web app to handle the changes (if any) to the database on tomcat startup/context startup. I want to release this application to the public, but I don't know what is the best model to do this. Do most people just use a servlet to handle this operation, or maybe a ContextListener? I just wanted to ping everyone and see if there was a best practice.
Thanks in advance!
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
This isn't JSF specific, incidentally.
If you're going to dynamically modify the schema from within a webapp, probably the best way to do it is to have a servlet that runs the mods in its init() method and setup web.xml so that that servlet runs first, before any other servlets. That way no one will attempt to access the database while you're modifying it.
In actual practice, I think a lot of people just run the mods as a request from a standard servlet and make the request right after they restart the server. That's a questionable practice, since stuff like that may take longer than a request processor should be taking, and it does risk concurrent accesses by other users while that's going on. But a lot of people don't care.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
As a general rule of thumb, software changes should result in the least amount of database changes if at all possible. While this can lead to poorly named and unused database fields, the risk of changing the database is significantly reduced. Keep in mind, a single database change could halt an entire application if it breaks enough queries.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
 |
|
|
subject: Database Schema Updates
|
|
|