On 11/16/2015 02:23 AM, Jeff Widman wrote:
> Thanks Mike. That helped tremendously.
>
> A couple of followup questions:
> (questions based on this code extending the view recipe:
>
https://gist.github.com/jeffwidman/1656498de21dc0afcdab)
>
> 1) In the recipe for creating views, I see:
>
> CreateView(name, selectable).execute_at('after-create', metadata)
>
>
> But in the docs it looks like this 'execute_at()' method is deprecated
> <
http://docs.sqlalchemy.org/en/latest/core/ddl.html#sqlalchemy.schema.DDLElement.execute_at>,
> should I be doing something different?
execute_at is not really going to go away but the new way is
execute_if(), as detailed at
http://docs.sqlalchemy.org/en/latest/core/ddl.html#sqlalchemy.schema.DDLElement.execute_if
> Also, not clear to my why this method is deprecated,
because once the event system was added it became clear that the
execute_at() system was redundant, and it's always a good idea to
express as many behaviors as possible via the fewest number of internal
mechanisms.
especially since
> the descriptions on that page for several other methods say 'see
> execute_at() for more information' so it doesn't exactly "feel" deprecated.
I see it just at DDLElement.execute() where that doc should be updated.
Where else?
>
>
> 2) What is the preferred way to create a unique index on the
> materialized view? PostgreSQL requires the index in order to refresh the
> view concurrently.
Index(..., unique=True) should work?
>
> I tried calling the normal Index function, but it threw an exception
> when I passed it a materialized view object
what exception?
(but worked perfectly when I
> passed a table object, so I know it's not incorrect params).
OK this might be because that recipe uses a lower-case "table()" object
which is not as full featured as Table, i'd alter the recipe to use
Table perhaps
So instead,
> I created a new subclass of DDLElement specifically for indexing
> materialized views... you can see it in the gist, and it works fine,
> just not sure if there's a better way.
sounds like a good workaround
>
>
> 3) How do I set this index-creating-ddlelement to trigger (using
> sqlalchemy events) after the materialized view is created?
>
> Currently I first call CreateView_DDLElement.execute_at('after-create',
> db.metadata), and then immediately after call
> CreateViewIndex_DDLElement.execute_at('after-create', db.metadata). So
> far it's worked fine, but there's a potential for the 'create index' to
> be called before 'create view' since they both are listening for the
> same event. So how do I set this index to be triggered on completion of
> creating the view?
so there are event hooks for "after table create" and "after metadata
create" but not "after my custom DDLElement create", which might be a
problem, although, the events here are run in deterministic order based
on when they were assigned as listeners. Or you might want to
implement a custom "after_create" listener that just calls upon
CreateView create and CreateViewIndex directly.
>
> More than happy to submit a PR helping tidy up the docs on this, just
> not sure what I should be saying.
well we'd have to see what we get at the end and if it looks usable or
not. I guess this would all be part of that recipe for now. An
eventual feature would draw from all the lessons learned here.
> <mailto:
sqlalchemy%2Bunsu...@googlegroups.com>
> > <mailto:
sqlalchemy+...@googlegroups.com
> <mailto:
sqlalchemy%2Bunsu...@googlegroups.com>>.
> > <mailto:
sqlal...@googlegroups.com
> <mailto:
sqlalchemy%2Bunsu...@googlegroups.com>.
> *
> Jeff Widman*
>
jeffwidman.com <
http://www.jeffwidman.com/> | 740-WIDMAN-J (943-6265)
> <><
> ᐧ