On Sep 1, 2014, at 10:49 AM, Wouter van Bommel <[email protected]> wrote:
> Hi All, > > Currently I am trying to figure out the best way to solve the following > problem. > > I have a database with 16 tables, defined in 16 declarative object > definitions. This all works as expected. > > The problem I am now facing is that from one of the definitions I do need 2 > versions, which are nearly identical ( the difference is the change of some > column types and some additional columns). > typically you put what's common to both on a mixin, then have those models inherit from the mixin: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative.html#mixin-and-custom-base-classes > Which is the best way to get this implemented while being able to have both > versions active at the same time, with a bind to 2 different database > engine(s). the two database part should be seen as something separate from model declaration, and depends on how these models are used. The cleanest way, if it works, is to set up the Session on those two engines on a per-mapper basis. Session's API here is a little out of date but there's an approach you can use at http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/ which shows how you can override get_bind() to do what you need; in that example, you can also see how to separate the two model hierarchies with different MetaData bases.. Or just keep those databases totally separate and use two Sessions, sometimes that is the appropriate way to go (certainly the simplest). I actually had a project that was exactly of this nature awhile back, the two separate hierarchies were destined completely for two different places and weren't handled together, so the app had two sessions. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
