views:

37

answers:

2

I'm looking to write a few small tools for managing table content for an existing SQL Server 2005 DB. I have a few dozen tables of reference content for an application that is deployed on many client databases (often for different schema versions) and I want to build a few python scripts to export, import, diff, and merge this content across versions while maintaining referential integrity. Is there a simple way to automatically generate python classes to model this content for each database release? I am primarily a sql developer with only a bit of python and java experience, so the simpler the better.

EDIT: Forgot to mention that I'd not only like to be able to create the model, but also easily populate the objects from an existing db.

A: 

Django has documentation on using it with legacy databases, but you will still have to handle things such as specifying relations yourself.

Ignacio Vazquez-Abrams
Django seems to revolve around building a web app which is overkill for my purposes (for now I don't even need a UI). Is it possible to extract just the database functionality (create model, read from db, persist to db) without having to configure a full web project?
Gus
If you don't need the web functionality then don't bother with Django. You can use the ORM on its own, but there are better.
Ignacio Vazquez-Abrams
+1  A: 

SqlAlchemy may actually help you . You can have a look here http://www.sqlalchemy.org/docs/05/ormtutorial.html

This seems close to what I need:http://www.sqlalchemy.org/docs/05/metadata.html#reflecting-tables, but it seems to work only for a live db connection. Is there a way to persist the table definition to a file after reflecting from the db. I need to be able to store objects for more than one schema version at a time, and then probe the live db to know which version to import to/export from.
Gus
Consider storing the schema version information in the database itself.
Ignacio Vazquez-Abrams