On Friday 08 December 2006 16:55, Ed Singleton wrote:
> I had posted this to the TurboGears list, but just realised that this
> may be a more appropriate place for it.
> Any help on using SQLObject to create sql files greatly appreciated.
> ---------- Forwarded message ----------
> From: Ed Singleton <singletoned@...>
> Date: 08-Dec-2006 11:08
> Subject: Converting between Databases
> To: turbogears@...
> Is there anyway with SQLObject to output all the sql necessary to
> recreate your table with the data as well as the table definitions?
> If so would it be possible to connect to a Postgres database and
> create the sql for an sqlite database?
> As SQLObject clearly can create the sql for all these databases, it
> seems like it should be possible.
Nope. Because with SQLObject, your model defines what your SQL looks like. And
it is straightforward to write generators to spit out the appropriate sql for
every supported backend.
But the other way round - recreating a model from a DB-schema - isn't an easy
task. To say the least. For example, sqlite doesn't know anything about
referential integrity - so how do you infer which objects (and thus tables)
are supposed to be related to each other using foreign key connstraints?
This kind of roundtrip-engineering has been a dream for a lot of things all
the time - think of UML generating classes, which in turn reflect
modifications in the UML. Or GUI-builders that create code, and changing the
code changes the GUI-builders. All of these have failed miserably.
So - it's a wasted effort to even try, IMHO.
BUT if you have a model, which you used to create the sqlite DB with, chances
are that you could make things work. Because then you could try and create a
pickle or something from a in-memory representation of your object graph,
switch the DB-config, and store it away again. However, I'm not aware of an