sqlalchemy / sqlalchemy/alembic

Autogenerate does not consider schema for enum type

Open
#899 24 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate for enums bug missing behavior
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
I am using Postgres 12, Alembic (1.7.1) and SQLAlchemy (1.4.23)
and have something like this SQLAlchemy enum in my model:

class MyEnum(enum.Enum):
    one= 'one'
    two= 'two'

...

my_enum = Column(Enum(MyEnum), nullable=False)

When I run
alembic revision --autogenerate

I get in my migration script:

sa.Column('my_enum',
          sa.Enum('one', 'two', name='myenum'),
          nullable=False),

I am using another schema than the default (public) one and while there is a schema arg that can be set (and I am currently changing the script manually adding it), it is not being considered by autogenerate. For stuff like tables and so on, it works perfectly and the schema is considered.

Expected behavior
I'd like to see the following being autogenerated for my example case:

sa.Column('my_enum',
          sa.Enum('one', 'two', name='myenum', schema='my_schema_name'), 
          nullable=False),

Versions.

  • OS: Ubuntu 20.04
  • Python: 3.8.10
  • Alembic: 1.7.1
  • SQLAlchemy: 1.4.23
  • Database: Postgres 12
  • DBAPI:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with alembic revision --autogenerate using a non-public schema and inspect the generated migration script for the SQLAlchemy Enum column. Trace how autogenerate handles the Enum schema argument, then verify that the generated sa.Enum includes the model's schema without manual edits.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sqlalchemy
Domain
databases, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.