Pogchamp-company/alembic-postgresql-enum

Failing to use on existing Postgres enum

idomic opened this issue ยท 6 comments

idomic commented

I have an enum (ProjectType):

from enum import Enum


class CustomEnum(Enum):
    @classmethod
    def get_values(cls):
        return [e.value for e in cls]

class ProjectType(CustomEnum):
    APPRUNNER = "aws-apprunner"
    ECS = "ecs"
    CONVERT = "notebook-convert"

Now I've also added this to the env.py:
import alembic_postgresql_enum

The moment I'm running alembic revision --autogenerate -m 'enum fix' I get this error:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near "(": syntax error
[SQL: 
        SELECT
            pg_catalog.format_type(t.oid, NULL),
            ARRAY(SELECT enumlabel
                  FROM pg_catalog.pg_enum
                  WHERE enumtypid = t.oid)
        FROM pg_catalog.pg_type t
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
        WHERE
            t.typtype = 'e'
            AND n.nspname = ?
    ]
[parameters: ('main',)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Any ideas what's going on?

idomic commented

I also have a table where I create a column with the postgres defaults:

visibility = Column(
        Enum(*Visibility.get_values(), name="visibility")
    )

Now I'm adding the native_enum flag:

visibility = Column(
        Enum(*Visibility.get_values(), name="visibility", native_enum=False)
    )

Does this also autogenerates?

As I can see, you are using sqlite3, our library does not support it

visibility = Column(
        Enum(*Visibility.get_values(), name="visibility", native_enum=False)
    )

Does this also autogenerates?

Not at the moment, I will add support very soon

idomic commented

So I'm using sqlite3 for testing, but the actual dB is postgres 15. Is that not supported as well?

postgres 15 is supported

idomic commented

I simply used alter table and column type directly.