feat: add LOCAL_FOLDER_FILE document type and update document_versions table management

This commit is contained in:
Anish Sarkar 2026-04-02 21:01:31 +05:30
parent 8e58094a86
commit 40ade4889e

View file

@ -1,4 +1,4 @@
"""Add local folder connector enums and document_versions table """Add LOCAL_FOLDER_FILE document type and document_versions table
Revision ID: 117 Revision ID: 117
Revises: 116 Revises: 116
@ -21,23 +21,6 @@ PUBLICATION_NAME = "zero_publication"
def upgrade() -> None: def upgrade() -> None:
conn = op.get_bind() conn = op.get_bind()
# Add LOCAL_FOLDER_CONNECTOR to searchsourceconnectortype enum
op.execute(
"""
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_type t
JOIN pg_enum e ON t.oid = e.enumtypid
WHERE t.typname = 'searchsourceconnectortype' AND e.enumlabel = 'LOCAL_FOLDER_CONNECTOR'
) THEN
ALTER TYPE searchsourceconnectortype ADD VALUE 'LOCAL_FOLDER_CONNECTOR';
END IF;
END
$$;
"""
)
# Add LOCAL_FOLDER_FILE to documenttype enum # Add LOCAL_FOLDER_FILE to documenttype enum
op.execute( op.execute(
""" """
@ -126,9 +109,17 @@ def downgrade() -> None:
{"name": PUBLICATION_NAME}, {"name": PUBLICATION_NAME},
).fetchone() ).fetchone()
if pub_exists: if pub_exists:
op.execute( already_in_pub = conn.execute(
f"ALTER PUBLICATION {PUBLICATION_NAME} DROP TABLE IF EXISTS document_versions" sa.text(
) "SELECT 1 FROM pg_publication_tables "
"WHERE pubname = :name AND tablename = 'document_versions'"
),
{"name": PUBLICATION_NAME},
).fetchone()
if already_in_pub:
op.execute(
f"ALTER PUBLICATION {PUBLICATION_NAME} DROP TABLE document_versions"
)
op.execute("DROP INDEX IF EXISTS ix_document_versions_created_at") op.execute("DROP INDEX IF EXISTS ix_document_versions_created_at")
op.execute("DROP INDEX IF EXISTS ix_document_versions_document_id") op.execute("DROP INDEX IF EXISTS ix_document_versions_document_id")