Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I reuse an existing enum? #566

Closed
zzztimbo opened this issue May 23, 2019 · 2 comments
Closed

How do I reuse an existing enum? #566

zzztimbo opened this issue May 23, 2019 · 2 comments
Labels
data types duplicate This issue or pull request already exists missing behavior not quite a feature and not quite a bug, somehting we need to support postgresql

Comments

@zzztimbo
Copy link

zzztimbo commented May 23, 2019

Given:

from sqlalchemy import Column, Integer, String
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.ext.declarative import declarative_base

from ..shared.string import StateOrTerritory

Base = declarative_base()


class Bug(Base):
    __tablename__ = "bug"
    id = Column(Integer, primary_key=True)
    bug_tracker_url = Column(
        String, unique=True, comment="the bug tracker url"
    )
    state = Column(
        ENUM(
            *[
                state_or_territory.value
                for state_or_territory in StateOrTerritory
            ],
            name="state_or_territory",
            create_type=False,
            drop_type=False,
        ),
        nullable=False,
        comment="The state or territory in which the bug was created.",
    )

I'm using alembic revision --autogenerate -m "create bug table" and I don't see the create_type=False being generated in the migration file. This is what I see:

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bug',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('bug_tracker_url', sa.String(), nullable=True, comment='the bug tracker url'),
    sa.Column('user_state', postgresql.ENUM('AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MH', 'MA', 'MI', 'FM', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PW', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'VI', 'WA', 'WV', 'WI', 'WY', name='state_or_territory'), nullable=False, comment='The state or territory in which the applicant resides. This field is a part of the request.'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('bug_tracker_url')
    )
    # ### end Alembic commands ###

Is this question a dupe of this bug? #278

@zzzeek
Copy link
Member

zzzeek commented May 23, 2019

it is a dupe of #278, nothing is implemented in autogenerate for the special requirements of Posgresql enums right now. you need to propagate create_type=False manually for now.

@zzzeek zzzeek added data types duplicate This issue or pull request already exists missing behavior not quite a feature and not quite a bug, somehting we need to support postgresql labels May 23, 2019
@zzztimbo
Copy link
Author

thanks @zzzeek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data types duplicate This issue or pull request already exists missing behavior not quite a feature and not quite a bug, somehting we need to support postgresql
Projects
None yet
Development

No branches or pull requests

2 participants