Fix: remove unused imports and f-string formatting (#12935)

### What problem does this PR solve?

- Remove unused imports (Mock, patch, MagicMock, json, os,
RAGFLOW_COLUMNS, VECTOR_FIELD_PATTERN) from multiple files
- Replace f-string formatting with regular strings for console output
messages in cli.py
- Clean up unnecessary imports that were no longer being used in the
codebase

### Type of change

- [x] Refactoring
This commit is contained in:
Liu An
2026-02-02 12:11:39 +08:00
committed by GitHub
parent 332b11cf96
commit 1b587013d8
10 changed files with 12 additions and 20 deletions

View File

@ -50,7 +50,6 @@ class TextFieldType(Enum):
MYSQL = "LONGTEXT" MYSQL = "LONGTEXT"
OCEANBASE = "LONGTEXT" OCEANBASE = "LONGTEXT"
POSTGRES = "TEXT" POSTGRES = "TEXT"
POSTGRES = "TEXT"
class LongTextField(TextField): class LongTextField(TextField):

View File

@ -3,7 +3,6 @@ Tests for OceanBase Peewee ORM support.
""" """
import pytest import pytest
from unittest.mock import Mock, patch, MagicMock
from api.db.db_models import ( from api.db.db_models import (
RetryingPooledOceanBaseDatabase, RetryingPooledOceanBaseDatabase,
PooledDatabase, PooledDatabase,

View File

@ -15,7 +15,6 @@ from .es_client import ESClient
from .ob_client import OBClient from .ob_client import OBClient
from .migrator import ESToOceanBaseMigrator from .migrator import ESToOceanBaseMigrator
from .verify import MigrationVerifier from .verify import MigrationVerifier
from .schema import RAGFLOW_COLUMNS
console = Console() console = Console()
@ -115,7 +114,7 @@ def migrate(
indices_to_migrate = [(index, table if table else index)] indices_to_migrate = [(index, table if table else index)]
else: else:
# Auto-discover all ragflow_* indices # Auto-discover all ragflow_* indices
console.print(f"\n[cyan]Discovering RAGFlow indices...[/]") console.print("\n[cyan]Discovering RAGFlow indices...[/]")
ragflow_indices = es_client.list_ragflow_indices() ragflow_indices = es_client.list_ragflow_indices()
if not ragflow_indices: if not ragflow_indices:
@ -166,7 +165,7 @@ def migrate(
# Summary for multiple indices # Summary for multiple indices
if len(indices_to_migrate) > 1: if len(indices_to_migrate) > 1:
console.print(f"\n[bold]{'='*60}[/]") console.print(f"\n[bold]{'='*60}[/]")
console.print(f"[bold]Migration Summary[/]") console.print("[bold]Migration Summary[/]")
console.print(f"[bold]{'='*60}[/]") console.print(f"[bold]{'='*60}[/]")
console.print(f" Total indices: {len(indices_to_migrate)}") console.print(f" Total indices: {len(indices_to_migrate)}")
console.print(f" [green]Successful: {total_success}[/]") console.print(f" [green]Successful: {total_success}[/]")
@ -232,13 +231,13 @@ def schema(ctx, es_host, es_port, es_user, es_password, index, output):
# Vector fields # Vector fields
if analysis['vector_fields']: if analysis['vector_fields']:
console.print(f"\n[cyan]Vector fields detected:[/]") console.print("\n[cyan]Vector fields detected:[/]")
for vf in analysis['vector_fields']: for vf in analysis['vector_fields']:
console.print(f" - {vf['name']} (dimension: {vf['dimension']})") console.print(f" - {vf['name']} (dimension: {vf['dimension']})")
# Unknown fields # Unknown fields
if analysis['unknown_fields']: if analysis['unknown_fields']:
console.print(f"\n[yellow]Unknown fields (will be stored in 'extra'):[/]") console.print("\n[yellow]Unknown fields (will be stored in 'extra'):[/]")
for uf in analysis['unknown_fields']: for uf in analysis['unknown_fields']:
console.print(f" - {uf}") console.print(f" - {uf}")

View File

@ -18,7 +18,7 @@ from rich.progress import (
from .es_client import ESClient from .es_client import ESClient
from .ob_client import OBClient from .ob_client import OBClient
from .schema import RAGFlowSchemaConverter, RAGFlowDataConverter, VECTOR_FIELD_PATTERN from .schema import RAGFlowSchemaConverter, RAGFlowDataConverter
from .progress import ProgressManager, MigrationProgress from .progress import ProgressManager, MigrationProgress
from .verify import MigrationVerifier from .verify import MigrationVerifier

View File

@ -4,15 +4,14 @@ OceanBase Client for RAGFlow data migration.
This client is specifically designed for RAGFlow's data structure. This client is specifically designed for RAGFlow's data structure.
""" """
import json
import logging import logging
from typing import Any from typing import Any
from pyobvector import ObVecClient, FtsIndexParam, FtsParser, VECTOR, ARRAY from pyobvector import ObVecClient, FtsIndexParam, FtsParser, VECTOR, ARRAY
from sqlalchemy import Column, String, Integer, Float, JSON, Text, text, Double from sqlalchemy import Column, String, Integer, Float, JSON, Double
from sqlalchemy.dialects.mysql import LONGTEXT, TEXT as MYSQL_TEXT from sqlalchemy.dialects.mysql import LONGTEXT, TEXT as MYSQL_TEXT
from .schema import RAGFLOW_COLUMNS, ARRAY_COLUMNS, FTS_COLUMNS_TKS from .schema import RAGFLOW_COLUMNS, FTS_COLUMNS_TKS
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -4,7 +4,6 @@ Progress tracking and resume capability for migration.
import json import json
import logging import logging
import os
from dataclasses import dataclass, field, asdict from dataclasses import dataclass, field, asdict
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path

View File

@ -9,7 +9,7 @@ from typing import Any
from .es_client import ESClient from .es_client import ESClient
from .ob_client import OBClient from .ob_client import OBClient
from .schema import RAGFLOW_COLUMNS, ARRAY_COLUMNS, JSON_COLUMNS from .schema import ARRAY_COLUMNS, JSON_COLUMNS
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -7,7 +7,6 @@ import os
import tempfile import tempfile
import pytest import pytest
from pathlib import Path from pathlib import Path
from datetime import datetime
from es_ob_migration.progress import MigrationProgress, ProgressManager from es_ob_migration.progress import MigrationProgress, ProgressManager
@ -90,7 +89,7 @@ class TestProgressManager:
def test_create_progress_manager_creates_dir(self, temp_dir): def test_create_progress_manager_creates_dir(self, temp_dir):
"""Test that progress manager creates directory.""" """Test that progress manager creates directory."""
new_dir = os.path.join(temp_dir, "new_progress") new_dir = os.path.join(temp_dir, "new_progress")
manager = ProgressManager(progress_dir=new_dir) ProgressManager(progress_dir=new_dir)
assert Path(new_dir).exists() assert Path(new_dir).exists()
def test_create_progress(self, manager): def test_create_progress(self, manager):
@ -225,7 +224,7 @@ class TestProgressManager:
def test_can_resume_running(self, manager): def test_can_resume_running(self, manager):
"""Test can_resume for running migration.""" """Test can_resume for running migration."""
progress = manager.create_progress( manager.create_progress(
es_index="ragflow_resume_running", es_index="ragflow_resume_running",
ob_table="ragflow_resume_running", ob_table="ragflow_resume_running",
total_documents=1000, total_documents=1000,
@ -291,7 +290,7 @@ class TestProgressManager:
def test_progress_file_path(self, manager): def test_progress_file_path(self, manager):
"""Test progress file naming.""" """Test progress file naming."""
progress = manager.create_progress( manager.create_progress(
es_index="ragflow_abc123", es_index="ragflow_abc123",
ob_table="ragflow_abc123", ob_table="ragflow_abc123",
total_documents=100, total_documents=100,

View File

@ -9,7 +9,6 @@ This module tests:
""" """
import json import json
import pytest
from es_ob_migration.schema import ( from es_ob_migration.schema import (
RAGFlowSchemaConverter, RAGFlowSchemaConverter,
RAGFlowDataConverter, RAGFlowDataConverter,

View File

@ -2,9 +2,8 @@
Tests for migration verification. Tests for migration verification.
""" """
import json
import pytest import pytest
from unittest.mock import Mock, MagicMock from unittest.mock import Mock
from es_ob_migration.verify import MigrationVerifier, VerificationResult from es_ob_migration.verify import MigrationVerifier, VerificationResult