Hi,

I'm curious if there's a best practice for generating tables with a
prefix in TG2 as defined in the application's .ini files. This is
probably a non-issue for most projects, but assuming an end user
happens to have exactly one database, I'm sure they wouldn't want to
run into naming conflicts!

So far, I have only three ideas. Here they are in order from worst to
slightly better:

1) Adding model imports to the init_model() function from the model's
__init__.py. This works since the model is defined after the
environment is loaded, but it's *really* wrong for a couple of
reasons. First, I need the model to be defined first and foremost for
other things (namely repoze), and second, it seems that using
init_model() is intended for going the opposite route of creating
model objects from a database that already exists.

Importing the model late in the application set up sort of works for
doing something like this for each table object for a simple app:

class SomeTable (DeclarativeBase):
    __tablename__ = config.get("database.table.prefix")+'sometable'

2) Hard-coding a prefix--sort of defeats the purpose.

3) Creating the tables using a separate SQL script specific to the
target database. Or maybe even a separate installer using SQLAlchemy.
This seems to be a better route than #1 and #2. Then, I suppose I
could use SQLAlchemy's reflection to set up the model. I'd imagine I
could probably do something using paster's setup-app to make this
somewhat automated.

I can get away with #1 for fairly simple applications, but it doesn't
feel right. Plus, the moment authorization using repoze is enabled, it
seems I run into a slight chicken-versus-egg problem using this
approach. Leaving it as it is in #1 causes all kinds of messy problems
since the model doesn't exist by the time repoze is setup. Moving the
imports from #1 in the model's __init__ module to where they're
supposed to be (at the bottom--outside init_model()) causes a mess
since the configuration object isn't fully setup, and config.get()
returns None.

I know there's something I'm missing, and it may be pretty obvious.
Maybe it's something in the SQLAlchemy docs I've no doubt overlooked?
Or, perhaps I'm just down on myself for being completely unable to see
what the best course of action is!

-- 
Benjamin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to