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 at 1:00 am by MrNate

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.

Post A Comment!
On Aug 12, 2006 at 11:00 PM barry.b (barry.beattie, who eats gmail.com) said:
thankyou for blogging this. having this grief has only ever happened to me once years ago....
.... but it's nice to think Reactor can provide a safety net...

thanx also for your build script.
Post A Comment!