I’d like to create a routine for renaming foreign key constraints in our database (one of our migration steps). I ended up creating this routine, which works, but it’s a bit ugly, and I expect brittle: http://paste.turbogears.org/paste/94119.
This implementation is clumsy because, as I understand it,
(a) There’s no way to query for a foreign key constraint by name.
(b) There’s no straightforward way to get all foreign key constraints for a database.
(c) A migrate.changeset.constraint.ForeignKeyConstraint must be constructed that matches the existing constraint.
(d) There’s no easy way to construct a migrate.changeset.constraint.ForeignKeyConstraint from a sqlalchemy.schema.ForeignKeyConstraint.
(e) Using the same ForeignKeyConstraint for the drop and create operation (only changing the name in between) fails (SQL syntax error with the child/local column list empty).
I’m hoping that I’m mistaken and that there’s a more elegant way to accomplish what I’m trying to do.
Is there something I’m missing that could help accomplish this seemingly simple operation?
Regards,
Jason