- attached 3442.patch
no control of DDL sequences for indexes, FK constraints that are mutually dependent
Issue #3442
new
the whole system described at http://docs.sqlalchemy.org/en/rel_1_0/core/ddl.html#controlling-ddl-sequences only takes place for constraints that are rendered inline within the table definition via the _create_rule() callable checked in compiler.py. This callable is not consulted anywhere in ddl.py when it goes to create indexes, foreign keys, or for that matter sequences.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
x = Column(Integer)
favorite_b = Column(Integer)
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
a_id = Column(Integer)
from sqlalchemy.schema import CreateIndex, AddConstraint
idx = Index('aidx', A.x)
fk1 = ForeignKeyConstraint([B.a_id], [A.id], name='afk')
fk2 = ForeignKeyConstraint([A.favorite_b], [B.id], name='bfk')
from sqlalchemy import event
event.listen(
Base.metadata,
'after_create',
CreateIndex(idx).execute_if(dialect='postgresql')
)
event.listen(
Base.metadata,
'after_create',
AddConstraint(fk1).execute_if(dialect='postgresql')
)
event.listen(
Base.metadata,
'after_create',
AddConstraint(fk2).execute_if(dialect='postgresql')
)
e = create_engine("mysql://scott:tiger@localhost/test", echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)
Comments (6)
-
reporter -
reporter - rework the "controlling DDL sequences" documentation to refer mostly to the DDL object; this system is primarily useful in that case, and not for built-in objects. Reference that the built-in case is not really viable right now. References #3442.
→ <<cset e0a8030048f4>>
-
reporter - rework the "controlling DDL sequences" documentation to refer mostly to the DDL object; this system is primarily useful in that case, and not for built-in objects. Reference that the built-in case is not really viable right now. References #3442.
→ <<cset 2759ec3e8a3a>>
-
reporter - rework the "controlling DDL sequences" documentation to refer mostly to the DDL object; this system is primarily useful in that case, and not for built-in objects. Reference that the built-in case is not really viable right now. References #3442.
→ <<cset f71596bdd576>>
-
reporter docs are updated that this is mostly useful for DDL and custom DDLElement subclasses. There's no pressing need for this to work with built-ins, pushing out for a revisit later.
-
reporter - Log in to comment
partial patch. tests need improvement.