sqlalchemy / sqlalchemy/alembic
checkfirst feature ?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the migration operation APIs and EnvironmentContext, then trace how Inspector is created and cached for one migration script. Compare add_X and drop_X operations with alter_column(), and verify the proposed checkfirst forms preserve migration-wide semantics while avoiding repeated per-column queries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100