olirice / alembic_utils

An alembic/sqlalchemy extension for migrating sql views, functions, triggers, and policies
https://olirice.github.io/alembic_utils
MIT License
211 stars 43 forks source link

Adapting simulate_entities() to use .begin() instead of .begin_nested() #124

Closed bpercy11 closed 8 months ago

bpercy11 commented 8 months ago

https://github.com/olirice/alembic_utils/blob/cf42ef81535670cd0e3c84111ae100a95c6b9205/src/alembic_utils/simulate.py#L17

I’m attempting to adapt alembic-utils to function with AWS Redshift. Aside from having to alter some of the queries against pg_* tables that don’t exist in redshift, an issue I have tried and failed to solve is converting the simulate.py’s simulate_entity() method to use session.begin() instead of session.begin_nested(). This is due to the fact that redshift does not have any implementation for SAVEPOINT which .begin_nested() uses which will throw errors when autogenerating materialized views via Alembic cli.

Having wrote the original method, could you help me in converting this?

Thank you!

olirice commented 8 months ago

There's some related info in https://github.com/olirice/alembic_utils/issues/123 about redshift

simulate_entity is highly reliant on savepoints/subtransactions for dependency resolution and exception handling. Unfortunately I don't think it feasible to remove that dependency.

if you're willing to forego dependency resolution entirely (your models don't depend on each other) might be able to strip out all the sub transaction stuff and just retain

https://github.com/olirice/alembic_utils/blob/cf42ef81535670cd0e3c84111ae100a95c6b9205/src/alembic_utils/simulate.py#L47-L50

but I'm not 100% on that