Ability to avoid duplicate alembic comparator dispatch with `registered_entities`
See original GitHub issueHas some resemblance to https://github.com/olirice/alembic_utils/issues/56, or at least covers the same code, but i think is a different problem.
I’m using https://github.com/schireson/pytest-alembic to test my migrations, which ends up reexecuting the env.py
many times within a single process (in many cases, once per migration), which leads to the same comparator getting reregistered numerous times. It’s doesn’t break alembic, but it does get progressively slower.
Due to the way register_entities
works (https://github.com/olirice/alembic_utils/blob/bdaa374d27c597ba79cd1d0b56ea5d3e87404a07/src/alembic_utils/replaceable_entity.py#L208), there’s not a great way to hook it into alembic without this happening.
A random example of how this could be avoided through a change to alembic_utils, might look like
@dataclass
class Registry:
entities: List
def register_entities(self, ...):
"""I'm what is now `register_entities`."""
registry = Registry()
register_entities = registry.register_entities
@comparators.dispatch_for("schema")
def compare_registered_entities(...):
...
This suggestion is sort-of based on how sqlalchemy/alembic themselves do things, but there are other, probably less drastic options. For example, just defining the functions in such a way that i could make the call to comparators.dispatch_for
myself.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top GitHub Comments
Thanks for this improvement, we literally went from 10 minutes to 4 minutes in our CI just upgrading to alembic_utils 0.7.7 🎉 FYI we are using both libraries, pytest-alembic and alembic-utils !
Love to see it, just upgraded and all seems well for our migrations. thanks!