sqlalchemy / sqlalchemy/alembic
op.add_column() and op.drop_column() should check for SchemaType, run through the events for that type, or perhaps just create/drop
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 Wichert Akkerman (@wichert)
I have a data model which has a simple enum column:
size_type = schema.Column(
types.Enum('normal', 'plus', name='size_type_type'),
nullable=False, default='normal')
as part of an upgrade routine I need to add that column if it is missing:
alembic.add_column('article_variant',
ArticleVariant.__table__.c['size_type'].copy())
alembic is an operation instance here. This operation breaks due to a missing check if the enum type already exists. The resulting error is:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) type "size_type_type" does not exist
LINE 1: ALTER TABLE article_variant ADD COLUMN size_type size_type_t...
^
'ALTER TABLE article_variant ADD COLUMN size_type size_type_type NOT NULL' {}
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 at the op.add_column() and op.drop_column() entry points and inspect how a copied SQLAlchemy Enum column is processed. Reproduce the shown migration with the size_type SchemaType, then verify that the operation handles the type's lifecycle consistently without the missing-type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100