-- Knowledge source binding projection 是按作品读回的读模型；同一来源 KB 可被同一用户绑定到多个作品。
-- 旧唯一键缺少 work_id，会把合法的跨作品复用误判为冲突。
ALTER TABLE muse_knowledge_source_binding_projection
    DROP CONSTRAINT IF EXISTS uk_muse_knowledge_source_projection_scope;

DROP INDEX IF EXISTS uk_muse_knowledge_source_projection_scope;

CREATE UNIQUE INDEX uk_muse_knowledge_source_projection_scope
    ON muse_knowledge_source_binding_projection(tenant_id, owner_user_id, work_id, source_owner, source_type, source_id, kb_id)
    WHERE deleted = FALSE;
