refactor: update column drop logic in DBMigrateModelProviderRefactor for PostgreSQL compatibility

This commit is contained in:
Junyan Qin
2025-12-29 20:42:06 +08:00
parent b788858f9e
commit 863b26c3fa
@@ -247,9 +247,14 @@ class DBMigrateModelProviderRefactor(migration.DBMigration):
deprecated_llm_cols = ['requester', 'requester_config', 'api_keys', 'description', 'source', 'space_model_id'] deprecated_llm_cols = ['requester', 'requester_config', 'api_keys', 'description', 'source', 'space_model_id']
for col in deprecated_llm_cols: for col in deprecated_llm_cols:
if col in llm_columns: if col in llm_columns:
await self.ap.persistence_mgr.execute_async( if self.ap.persistence_mgr.db.name == 'postgresql':
sqlalchemy.text(f'ALTER TABLE llm_models DROP COLUMN IF EXISTS {col}') await self.ap.persistence_mgr.execute_async(
) sqlalchemy.text(f'ALTER TABLE llm_models DROP COLUMN IF EXISTS {col}')
)
else:
await self.ap.persistence_mgr.execute_async(
sqlalchemy.text(f'ALTER TABLE llm_models DROP COLUMN {col}')
)
embedding_columns = await self._get_columns('embedding_models') embedding_columns = await self._get_columns('embedding_models')
deprecated_embedding_cols = [ deprecated_embedding_cols = [
@@ -262,9 +267,14 @@ class DBMigrateModelProviderRefactor(migration.DBMigration):
] ]
for col in deprecated_embedding_cols: for col in deprecated_embedding_cols:
if col in embedding_columns: if col in embedding_columns:
await self.ap.persistence_mgr.execute_async( if self.ap.persistence_mgr.db.name == 'postgresql':
sqlalchemy.text(f'ALTER TABLE embedding_models DROP COLUMN IF EXISTS {col}') await self.ap.persistence_mgr.execute_async(
) sqlalchemy.text(f'ALTER TABLE embedding_models DROP COLUMN IF EXISTS {col}')
)
else:
await self.ap.persistence_mgr.execute_async(
sqlalchemy.text(f'ALTER TABLE embedding_models DROP COLUMN {col}')
)
async def _get_columns(self, table_name: str) -> list: async def _get_columns(self, table_name: str) -> list:
"""Get column names for a table""" """Get column names for a table"""