From ca0f186b0e269e1d9b2b034f206a76a1e2c0dc30 Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Fri, 27 Oct 2023 12:13:57 -0700 Subject: [PATCH] Remove all in-postgres Enums (#637) --- .../3c5e35aa9af0_polling_document_count.py | 1 + .../46625e4745d4_remove_native_enum.py | 30 +++++++++++++++++++ .../47433d30de82_create_indexattempt_table.py | 2 +- ...45c915d0e_remove_deletion_attempt_table.py | 1 - ...0c7ad8a076_added_deletion_attempt_table.py | 8 ++--- 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 backend/alembic/versions/46625e4745d4_remove_native_enum.py diff --git a/backend/alembic/versions/3c5e35aa9af0_polling_document_count.py b/backend/alembic/versions/3c5e35aa9af0_polling_document_count.py index 2950d1f34..311031f81 100644 --- a/backend/alembic/versions/3c5e35aa9af0_polling_document_count.py +++ b/backend/alembic/versions/3c5e35aa9af0_polling_document_count.py @@ -35,6 +35,7 @@ def upgrade() -> None: "SUCCESS", "FAILED", name="indexingstatus", + native_enum=False, ), nullable=False, ), diff --git a/backend/alembic/versions/46625e4745d4_remove_native_enum.py b/backend/alembic/versions/46625e4745d4_remove_native_enum.py new file mode 100644 index 000000000..beb677d5e --- /dev/null +++ b/backend/alembic/versions/46625e4745d4_remove_native_enum.py @@ -0,0 +1,30 @@ +"""Remove Native Enum + +Revision ID: 46625e4745d4 +Revises: 9d97fecfab7f +Create Date: 2023-10-27 11:38:33.803145 + +""" +from alembic import op +from sqlalchemy import String + +# revision identifiers, used by Alembic. +revision = "46625e4745d4" +down_revision = "9d97fecfab7f" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # At this point, we directly changed some previous migrations, + # https://github.com/danswer-ai/danswer/pull/637 + # Due to using Postgres native Enums, it caused some complications for first time users. + # To remove those complications, all Enums are only handled application side moving forward. + # This migration exists to ensure that existing users don't run into upgrade issues. + op.alter_column("index_attempt", "status", type_=String) + op.execute("DROP TYPE IF EXISTS indexingstatus") + + +def downgrade() -> None: + # We don't want Native Enums, do nothing + pass diff --git a/backend/alembic/versions/47433d30de82_create_indexattempt_table.py b/backend/alembic/versions/47433d30de82_create_indexattempt_table.py index 58fa06d3b..597c698ab 100644 --- a/backend/alembic/versions/47433d30de82_create_indexattempt_table.py +++ b/backend/alembic/versions/47433d30de82_create_indexattempt_table.py @@ -59,6 +59,7 @@ def upgrade() -> None: "SUCCESS", "FAILED", name="indexingstatus", + native_enum=False, ), nullable=False, ), @@ -70,4 +71,3 @@ def upgrade() -> None: def downgrade() -> None: op.drop_table("index_attempt") - sa.Enum(name="indexingstatus").drop(op.get_bind(), checkfirst=False) diff --git a/backend/alembic/versions/d5645c915d0e_remove_deletion_attempt_table.py b/backend/alembic/versions/d5645c915d0e_remove_deletion_attempt_table.py index 964809942..120d63e16 100644 --- a/backend/alembic/versions/d5645c915d0e_remove_deletion_attempt_table.py +++ b/backend/alembic/versions/d5645c915d0e_remove_deletion_attempt_table.py @@ -18,7 +18,6 @@ depends_on = None def upgrade() -> None: op.drop_table("deletion_attempt") - sa.Enum(name="deletionstatus").drop(op.get_bind(), checkfirst=False) def downgrade() -> None: diff --git a/backend/alembic/versions/df0c7ad8a076_added_deletion_attempt_table.py b/backend/alembic/versions/df0c7ad8a076_added_deletion_attempt_table.py index 41c4a2184..4ccad3ff0 100644 --- a/backend/alembic/versions/df0c7ad8a076_added_deletion_attempt_table.py +++ b/backend/alembic/versions/df0c7ad8a076_added_deletion_attempt_table.py @@ -17,7 +17,6 @@ depends_on = None def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### op.create_table( "document", sa.Column("id", sa.String(), nullable=False), @@ -32,6 +31,7 @@ def upgrade() -> None: "VECTOR", "KEYWORD", name="documentstoretype", + native_enum=False, ), nullable=False, ), @@ -55,6 +55,7 @@ def upgrade() -> None: "SUCCESS", "FAILED", name="deletionstatus", + native_enum=False, ), nullable=False, ), @@ -101,15 +102,10 @@ def upgrade() -> None: ), sa.PrimaryKeyConstraint("id", "connector_id", "credential_id"), ) - # ### end Alembic commands ### def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### op.drop_table("document_by_connector_credential_pair") op.drop_table("deletion_attempt") op.drop_table("chunk") op.drop_table("document") - sa.Enum(name="deletionstatus").drop(op.get_bind(), checkfirst=False) - sa.Enum(name="documentstoretype").drop(op.get_bind(), checkfirst=False) - # ### end Alembic commands ###