diff --git a/backend/open_webui/migrations/versions/c0fbf31ca0db_update_file_table.py b/backend/open_webui/migrations/versions/c0fbf31ca0db_update_file_table.py index 709b644150..75eada2d3f 100644 --- a/backend/open_webui/migrations/versions/c0fbf31ca0db_update_file_table.py +++ b/backend/open_webui/migrations/versions/c0fbf31ca0db_update_file_table.py @@ -19,10 +19,17 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade(): + conn = op.get_bind() + inspector = sa.inspect(conn) + file_cols = {c['name'] for c in inspector.get_columns('file')} + # ### commands auto generated by Alembic - please adjust! ### - op.add_column('file', sa.Column('hash', sa.Text(), nullable=True)) - op.add_column('file', sa.Column('data', sa.JSON(), nullable=True)) - op.add_column('file', sa.Column('updated_at', sa.BigInteger(), nullable=True)) + if 'hash' not in file_cols: + op.add_column('file', sa.Column('hash', sa.Text(), nullable=True)) + if 'data' not in file_cols: + op.add_column('file', sa.Column('data', sa.JSON(), nullable=True)) + if 'updated_at' not in file_cols: + op.add_column('file', sa.Column('updated_at', sa.BigInteger(), nullable=True)) def downgrade(): diff --git a/backend/open_webui/migrations/versions/c29facfe716b_update_file_table_path.py b/backend/open_webui/migrations/versions/c29facfe716b_update_file_table_path.py index 9836708908..a08485f87f 100644 --- a/backend/open_webui/migrations/versions/c29facfe716b_update_file_table_path.py +++ b/backend/open_webui/migrations/versions/c29facfe716b_update_file_table_path.py @@ -20,8 +20,13 @@ depends_on = None def upgrade(): + conn = op.get_bind() + inspector = sa.inspect(conn) + file_cols = {c['name'] for c in inspector.get_columns('file')} + # 1. Add the `path` column to the "file" table. - op.add_column('file', sa.Column('path', sa.Text(), nullable=True)) + if 'path' not in file_cols: + op.add_column('file', sa.Column('path', sa.Text(), nullable=True)) # 2. Convert the `meta` column from Text/JSONField to `JSON()` # Use Alembic's default batch_op for dialect compatibility.