[Sqlalchemy-tickets] [sqlalchemy] #2814: support for overriding existing @compiles directives
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-08-27 15:21:11
|
#2814: support for overriding existing @compiles directives
-------------------------+------------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone: 0.9.xx
Component: ext | Severity: major - 1-3 hours
Keywords: | Progress State: in queue
-------------------------+------------------------------------
perhaps sending it in as a **kw.
{{{
#!python
from sqlalchemy.ext.compiler import compiles
from alembic.ddl.base import AddColumn
# ideally, the @compiles system would have some way of getting
# us the "existing" @compiles decorator, so this part is the
# hack
specs = AddColumn.__dict__.get('_compiler_dispatcher').specs
existing_dispatch = specs.get('mysql', specs['default'])
@compiles(AddColumn, "mysql")
def add_column(element, compiler, **kw):
text = existing_dispatch(element, compiler, **kw)
if "after" in element.column.info:
text += " AFTER %s" % element.column.info['after']
return text
from sqlalchemy import Column, Integer
from alembic.migration import MigrationContext
from alembic.operations import Operations
ctx = MigrationContext.configure(dialect_name="mysql", opts={"as_sql":
True})
op = Operations(ctx)
op.add_column("t", Column('y', Integer))
op.add_column("t", Column('x', Integer, info={"after": "y"}))
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2814>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|