alembic
alembic copied to clipboard
checkfirst feature ?
Migrated issue, originally created by Michael Bayer (@zzzeek)
For making migrations "idempotent" for those working in online mode, and to expand upon #151, allow operations to run a "checkfirst" by using inspector.
op.add_column('myothertable', Column('foo', type), checkfirst=True)
Or another optional way it can be enabled, via context manager:
def upgrade():
with op.checkfirst():
op.create_table('mytable', <columns>)
op.add_column('myothertable', Column(...))
op.drop_column(...)
or even as a flag on EnvironmentContext. I think some will want all migration operations to include "checkfirst" where it is available.
"checkfirst" would be used all add_X / drop_X methods. It would not for the time being be used by alter_column(). The feature would work by building up an Inspector that will last for the lifetime of a single migration script, making use of the fact that results are cached, so if we want to check lots of add_column/drop_column, there'd only be one set of queries per table rather than query-per-column. The use contract would include that checkfirst is relative to the migration as a whole, and not relative to individual operations within the migration.
Shatil Rafiullah (@shatil) wrote:
I am following this feature with great interest :) Any idea what the timeline for it could be, @zzzeek? I would love to help, but am very unfamiliar with Alembic's code base.
Michael Bayer (@zzzeek) wrote:
I had no immediate plans to work on it, when i next get time to work on alembic I'll typically choose the things that people are needing the most. Haven't had much call for this one, I guess if you could round up some votes that would be something.