diff --git a/backend/open_webui/migrations/versions/af906e964978_add_feedback_table.py b/backend/open_webui/migrations/versions/af906e964978_add_feedback_table.py index 5c7b33a452..65dcf6f5f9 100644 --- a/backend/open_webui/migrations/versions/af906e964978_add_feedback_table.py +++ b/backend/open_webui/migrations/versions/af906e964978_add_feedback_table.py @@ -17,23 +17,28 @@ depends_on = None def upgrade(): - # ### Create feedback table ### - op.create_table( - 'feedback', - sa.Column('id', sa.Text(), primary_key=True), # Unique identifier for each feedback (TEXT type) - sa.Column('user_id', sa.Text(), nullable=True), # ID of the user providing the feedback (TEXT type) - sa.Column('version', sa.BigInteger(), default=0), # Version of feedback (BIGINT type) - sa.Column('type', sa.Text(), nullable=True), # Type of feedback (TEXT type) - sa.Column('data', sa.JSON(), nullable=True), # Feedback data (JSON type) - sa.Column('meta', sa.JSON(), nullable=True), # Metadata for feedback (JSON type) - sa.Column('snapshot', sa.JSON(), nullable=True), # snapshot data for feedback (JSON type) - sa.Column( - 'created_at', sa.BigInteger(), nullable=False - ), # Feedback creation timestamp (BIGINT representing epoch) - sa.Column( - 'updated_at', sa.BigInteger(), nullable=False - ), # Feedback update timestamp (BIGINT representing epoch) - ) + conn = op.get_bind() + inspector = sa.inspect(conn) + existing_tables = set(inspector.get_table_names()) + + if 'feedback' not in existing_tables: + # ### Create feedback table ### + op.create_table( + 'feedback', + sa.Column('id', sa.Text(), primary_key=True), # Unique identifier for each feedback (TEXT type) + sa.Column('user_id', sa.Text(), nullable=True), # ID of the user providing the feedback (TEXT type) + sa.Column('version', sa.BigInteger(), default=0), # Version of feedback (BIGINT type) + sa.Column('type', sa.Text(), nullable=True), # Type of feedback (TEXT type) + sa.Column('data', sa.JSON(), nullable=True), # Feedback data (JSON type) + sa.Column('meta', sa.JSON(), nullable=True), # Metadata for feedback (JSON type) + sa.Column('snapshot', sa.JSON(), nullable=True), # snapshot data for feedback (JSON type) + sa.Column( + 'created_at', sa.BigInteger(), nullable=False + ), # Feedback creation timestamp (BIGINT representing epoch) + sa.Column( + 'updated_at', sa.BigInteger(), nullable=False + ), # Feedback update timestamp (BIGINT representing epoch) + ) def downgrade(): diff --git a/backend/open_webui/migrations/versions/b2c3d4e5f6a7_add_scim_column_to_user_table.py b/backend/open_webui/migrations/versions/b2c3d4e5f6a7_add_scim_column_to_user_table.py index 8cb62af600..cf942ec8c0 100644 --- a/backend/open_webui/migrations/versions/b2c3d4e5f6a7_add_scim_column_to_user_table.py +++ b/backend/open_webui/migrations/versions/b2c3d4e5f6a7_add_scim_column_to_user_table.py @@ -19,7 +19,12 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: - op.add_column('user', sa.Column('scim', sa.JSON(), nullable=True)) + conn = op.get_bind() + inspector = sa.inspect(conn) + user_cols = {c['name'] for c in inspector.get_columns('user')} + + if 'scim' not in user_cols: + op.add_column('user', sa.Column('scim', sa.JSON(), nullable=True)) def downgrade() -> None: