Dear colleagues,

I would like to extend enum type in postgres using alembic and currently i
have to do the following:

name = 'my_type'
old_enum = sa.dialects.postgresql.ENUM('value1', 'value2', name=name)
new_enum = sa.dialects.postgresql.ENUM('value1', 'value2', 'value3',
name=name)

op.execute(f'ALTER TYPE {name} RENAME TO _{name}')
new_enum.create(op.get_bind())
op.execute(f'ALTER TABLE table1 ALTER COLUMN col1 TYPE {name} USING
col1::text::{name}')
op.execute(f'DROP TYPE _{name}')

Since 9.1 postgres supports adding new values to enum natively (added
queries below), is it possible to perform such request in alembic?
ALTER TYPE enum_type ADD VALUE 'new_value'; -- appends to list
ALTER TYPE enum_type ADD VALUE 'new_value' BEFORE 'old_value';
ALTER TYPE enum_type ADD VALUE 'new_value' AFTER 'old_value';

-- 
Kind regards,
Alexander.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy-alembic/CAMXowCahmsmL4VFsFCWy6L1HmoM_OuA7F6C1s3H27UCFnoa8jA%40mail.gmail.com.

Reply via email to