Manually handle the new Enum creation

Alembic does not handle postgres Enums correctly, so we need to manually
generate the new enum type.
See https://github.com/sqlalchemy/alembic/issues/278
This commit is contained in:
Tom Roussel 2024-03-16 10:53:50 +01:00
parent ee12618b3b
commit 9eb18f2f99

View file

@ -16,10 +16,16 @@ from ihatemoney.models import BillType
def upgrade(): def upgrade():
op.add_column("bill", sa.Column("bill_type", sa.Enum(BillType), server_default=BillType.EXPENSE.name)) billtype_enum = sa.Enum(BillType)
billtype_enum.create(op.get_bind(), checkfirst=True)
op.add_column("bill", sa.Column("bill_type", billtype_enum, server_default=BillType.EXPENSE.name))
op.add_column("bill_version", sa.Column("bill_type", sa.UnicodeText())) op.add_column("bill_version", sa.Column("bill_type", sa.UnicodeText()))
def downgrade(): def downgrade():
op.drop_column("bill", "bill_type") op.drop_column("bill", "bill_type")
op.drop_column("bill_version", "bill_type") op.drop_column("bill_version", "bill_type")
billtype_enum = sa.Enum(BillType)
billtype_enum.drop(op.get_bind())