Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm working on a project with multiple services that share a common database. I'd like to minimize the risk that operational errors cause data corruption and one of the cases I'd like to guard against is running stale code against a new DB.

That is, I'd like to somehow stamp the DB with a version and then have all services older than that version error out on startup. That way, once the DB is migrated, old code can't be started against the newer DB. Are there any off-the-shelf ways other folks have been tackling this? I'm using Django, but I'm also interested in solutions used by other frameworks.

share|improve this question

2 Answers

If you are using south you could write a middleware that checks to see if all the migrations in all the applications have been applied, if they haven't you could have it respond to every request with a hard coded maintenance warning.

You would, of course, want to run this only once.

share|improve this answer
I actually want to go the other way. The middleware would have to determine if there are any migrations that have been applied that don't exist in the code base, as that means that the DB is newer and the server process should bail. Though, strictly speaking, there doesn't need to be a schema migration to cause a non-backwards compatible data change. – Logan Bowers Aug 5 '11 at 23:38
Yes, but if you have a schema change without a migration, then you have (at least) two problems... – Matthew Schinckel Aug 6 '11 at 5:40
It can check that the migrations in the file system MATCH the database, if they don't then something is funny and you shouldn't run. – Rob Osborne Aug 6 '11 at 13:09

You could have a simple table the stores application vs minimum application version number.

Part of your upgrade DB scripts would populate this table. When the application starts up, it would check its version against the minimum version in the table and explode if its version is too low.

I am not aware of any existing package that does this, but it doesn't seem like much code to achieve. I like the idea.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.