On 12/02/2015 02:13 AM, Chris Withers wrote:
> On 02/12/2015 00:08, Mike Bayer wrote:
>> On 12/01/2015 02:49 PM, Chris Withers wrote:
>>>     - once at 'database creation' time, so set up some stored
>>>     procedures. (I know SQLAlchemy doesn't create databases itself, so
>>>     interested in the correct approach for this)
>>>
>>> So, thinking this through, how are non-table DDL elements added to a
>>> MetaData object such that create_all can find them?
>> any DDL() object is eventable with after_create, before_create, some
>> basic docs at:
>>
>> http://docs.sqlalchemy.org/en/rel_1_0/core/ddl.html#custom-ddl
> Right, but I'm thinking of DDL events that aren't logically tied to the
> creation of a table.
> For example: sequences, enums and stored procedures - these live at the
> same level as tables in my head, so the most-simple-thing-I-can-think-of
> would be:
> 
> Base = declarative_base()
> 
> class MyModel(Base):
>     __tablename__='foo'
>     ...
> 
> my_sequence = Sequence('bar')
> 
> Base.metadata.add(my_sequence)
> 
> So then I could do:
> 
> Base.metadata.create_all(engine)
> 
> ...to get both the table and the sequence created.
> 
> What's the right way to do this?

the example in the link above illustrates the event being associated
with the MetaData object directly.   That is, with the
metadata.create_all() method you refer to above, e.g.
event.listen(my_metadata, 'after_create', CreateSequence(my_sequence)).

However, in the specific case of a Sequence, Sequence itself has a
metadata argument for this purpose.   Sequence('bar', metadata=my_metadata).


http://docs.sqlalchemy.org/en/rel_1_0/core/defaults.html?highlight=sequence#sqlalchemy.schema.Sequence.params.metadata







> 
> Chris
> 
> -- 
> 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 sqlalchemy+unsubscr...@googlegroups.com
> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
> To post to this group, send email to sqlalchemy@googlegroups.com
> <mailto:sqlalchemy@googlegroups.com>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to