On Sep 1, 2011, at 9:38 PM, Arthur Kopatsy wrote:

> Thanks Michael.
> 
> I did indeed find out about this solution but that is not exactly the
> perfect solution. A migration may do more that just changing the
> schema (e.g. UPDATE queries or even python code to correctly transform
> the data). These sql statement do not have to go through slony. Only
> the DDL changes do.
> 
> Ideally I would like to be able to intercept all the DDL statements
> and transform them. Events do not allow me to do that. Is there a way
> to mock DDLElement maybe or define my own custom dialect? I am trying
> to find the right place to hook that up in the SA code but it is not
> obvious.

You can use connection execute events to intercept anything, though in 0.7 
these don't have the ability to "circumvent" the statement from actually being 
emitted to the database, though you can change what the actual statement is, 
perhaps changing it to a no-op or similar.

It's not clear to me how a migration that consists of DDL intermixed with 
UPDATE statements could function, if all the DDL were not actually executed at 
that point, but all the UPDATE statements were - don't the UPDATE statements 
rely upon DDL changes that just occurred prior ?

Unless your plan is to generate the SQL to that named script immediately and 
execute, as the script proceeds.

Still, in that case still easy enough to use a different engine, using 
MockDialect, for all the DDL specific operations.     It depends somewhat on 
what systems you have in place to generate and execute DDL operations.   Or the 
connection events approach could probably handle it as well.

http://www.sqlalchemy.org/docs/core/events.html#sqlalchemy.events.ConnectionEvents

the docs are a little incomplete here, if you use before_execute() you'd return 
what was passed:

def before_execute(conn, stmt, multiparams, params):
    return stmt, multiparams, params

event.listen(engine, "before_execute", before_execute, retval=True)

where "retval=True" means, Connection will use what you return as what it 
actually executes.


Yet another way might be to wrap all your DDL in a new kind of compiled 
construct that does the "write to a file - then execute that" thing.






-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to