support for overriding existing @compiles directives

Issue #2814 new
Michael Bayer
repo owner created an issue

perhaps sending it in as a **kw.

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']('default'))

@compiles(AddColumn, "mysql")
def add_column(element, compiler, **kw):
    text = existing_dispatch(element, compiler, **kw)
    if "after" in
        text += " AFTER %s" %['after']('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"}))

Comments (2)

  1. Log in to comment