The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

How to rebuild a destroyed database with Reactor

posted under category: Free Code For You on August 13, 2006 by Nathan

If your shared development database server happens to have a permenant multiple drive failure like ours did on Friday, and if the project you're working on hadn't been added to the backups yet, and if you're smart enough to be using Reactor to manage your database abstraction and/or be your ORM service of choice, you just may be in luck!

One of the great things about Reactor is it creates metadata objects on all the tables it touches. The typical appliation for this feature is usually code generation, like scaffolding and such. Easy, cross-platform database information is really useful, especially in open-source software where you don't know what the target platform will be.

Now, the first thing you should do in a disaster situation like I described, as soon as you realize you're screwed, back up your reactor files, specifically those in the reactor projects file. In fact, just back up the whole reactor folder because those files are version-specific.

Next, change your reactor.xml file to be in production mode. Production mode will keep it from attempting to introspect your database. If it can't find the table, it will throw an error, so let's switch the mode. While you're in there, make sure you point to the correct dsn - if the existing server is still down, make a new DSN on an empty database and point the reactor.xml file to it.

Finally, you'll need to build a tool to loop through the tables Reactor knows about and write the create table scripts. Here, you can have mine (it works with sql server 2000 +. Feel free to modify it, then buy, sell or trade it for goods on the open market. It's better than gold, in a pinch. Just don't hold me accountable if anything bad happens.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.