From: Mike Driscoll <kyoso...@gmail.com>
Date: Tue, 9 Jun 2009 09:35:46 -0700 (PDT)
Local: Tues, Jun 9 2009 12:35 pm
Subject: Re: How to setup multiple databases in TG2
Drat it all! I forgot this import too:
from tg.configuration import config
On Jun 9, 11:30 am, Mike Driscoll <kyoso...@gmail.com> wrote:
> Also note that the pylons_config module is imported like this:
> from pylons import config as pylons_config
> On Jun 9, 10:52 am, Mike Driscoll <kyoso...@gmail.com> wrote:
> > By popular request, I'm sticking what I did on here:
> > I used the pylons docs to figure out part of this:http://www.pylonshq.com/docs/en/0.9.7/models/#multiple-engines
> > Here are the files to change:
> > #--------------
> > # create 2 or more sqlalchemy urls
> > sqlalchemy.main.url = sqlite:///%(here)s/devdata.db
> > # -------------------------------------------
> > #--------------
> > # need to subclass AppConfig and
> > from sqlalchemy import engine_from_config
> > class MyAppConfig(AppConfig):
> > base_config = MyAppConfig()
> > # -------------------------------------------
> > #--------------
> > # Global session manager: DBSession() returns the Thread-local
> > maker2 = sessionmaker(autoflush=True, autocommit=False,
> > def init_model(engineOne, engineTwo):
> > DBSession.configure(bind=engineTwo)
> > secondSession.configure(bind=engineOne)
> > # you only need this metadata
> > Note that in websetup, there is a call to
> > model.metadata.create_all(bind=config['pylons.app_globals'].sa_engine)
> > So when you override AppConfig in app_cfg.py, you'll want to change
> > config['pylons.app_globals'].engineOne = engineOne
> > to
> > config['pylons.app_globals'].sa_engine = engineOne
> > Hope that helps others.
> > - Mike
> > On Jun 9, 9:10 am, Mike Driscoll <kyoso...@gmail.com> wrote:
> > > For the record, this was resolved. I didn't know how to set up the
> > > Thanks!
> > > Mike
> > > On Jun 5, 2:06 pm, percious <ch...@percious.com> wrote:
> > > > It's not too bad, but you have to do your own custom app setup, and
> > > > app_cfg.py:
> > > > from webapp.model import init_model
> > > > class MyAppConfig(AppConfig):
> > > > # Pass the engine to initmodel, to be able to introspect
> > > > base_config = MyAppConfig()
> > > > model/__init__.py:
> > > > import model.users
> > > > from model.users.mappers import *
> > > > from zope.sqlalchemy import ZopeTransactionExtension
> > > > # Global session manager. DBSession() returns the session object
> > > > DBSession = UsersDBSession = scoped_session(maker)
> > > > SamplesDBSession = scoped_session(maker3)
> > > > def init_model(users_engine, samples_engine):
> > > > global UsersDBSession, SamplesDBSession, users_metadata,
> > > > UsersDBSession.configure(bind=users_engine)
> > > > users_metadata.bind = users_engine
> > > > This is sort of an off-the cuff answer, we will provide a better one
> > > > Come find me on IRC if you need some more help.
> > > > cheers.
> > > > On Jun 4, 10:31 am, Mike Driscoll <kyoso...@gmail.com> wrote:
> > > > > Hi,
> > > > > According to Mark Ramm's blog, supporting multiple databases is
> > > > > I "think" I need to put multiple sqlalchemy.url's in my
> > > > > I'm pretty sure the init_model came from Perkins. Maybe he can tell me
> > > > > That would be great!
> > > > > Thanks,
> > > > > Mike
> > > > > On May 28, 12:47 pm, Mike Driscoll <kyoso...@gmail.com> wrote:
> > > > > > Hi,
> > > > > > I am having a little trouble wrapping my head around how to configure
> > > > > > I assume I need to comment out this line:
> > > > > > metadata = DeclarativeBase.metadata
> > > > > > and instead create three metadata instances based on MetaData(),
> > > > > > Finally, as I understand it, I can use the "init_model" function to do
> > > > > > Hopefully that stuff makes sense. I am using Python 2.5 and TG2 in a
> > > > > > Thanks!
> > > > > > Mike
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||