Files
Enterprise-Knowledge-Base/migrations/versioned/000014_backfill_models_tenant_id.up.sql
T
wizardchen e66ace9c14 refactor: Remove unused SQL migration files and clean up docker-compose configurations
- Deleted several SQL migration files related to agent configuration, cleanup of unreferenced models, MCP services, and web search configuration.
- Updated docker-compose files to remove references to obsolete SQL migration scripts, streamlining the development environment setup.
- Improved code maintainability by eliminating unnecessary files and configurations.
2025-12-01 21:54:04 +08:00

46 lines
1.0 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 14-backfill-models-tenant-id.up.sql
-- Backfill tenant_id in models table using knowledges records that share the same id
BEGIN;
WITH tenant_source AS (
-- 从 knowledge_bases 中取出各模型 ID(embedding / summary)及其 tenant_id
SELECT
kb.embedding_model_id AS model_id,
kb.tenant_id
FROM knowledge_bases kb
WHERE kb.tenant_id IS NOT NULL
AND kb.embedding_model_id IS NOT NULL
AND kb.embedding_model_id <> ''
UNION
SELECT
kb.summary_model_id AS model_id,
kb.tenant_id
FROM knowledge_bases kb
WHERE kb.tenant_id IS NOT NULL
AND kb.summary_model_id IS NOT NULL
AND kb.summary_model_id <> ''
UNION
-- rerank 模型
SELECT
kb.rerank_model_id AS model_id,
kb.tenant_id
FROM knowledge_bases kb
WHERE kb.tenant_id IS NOT NULL
AND kb.rerank_model_id IS NOT NULL
AND kb.rerank_model_id <> ''
)
UPDATE models m
SET tenant_id = ts.tenant_id
FROM tenant_source ts
WHERE m.id = ts.model_id
AND m.tenant_id = 0;
COMMIT;