feat(knowledge-base): implement per-user pinning for knowledge bases

Refactored the pinning mechanism for knowledge bases to be user-specific, allowing any user with read access to pin knowledge bases independently. This change includes the introduction of a new `user_kb_pins` table to manage pin states, replacing the previous tenant-wide pinning system. Updated relevant API endpoints and service logic to support this new functionality, ensuring that the UI reflects the user's personal pin status.

Additionally, adjusted the knowledge base listing to sort by user-specific pin status, enhancing the user experience by prioritizing pinned items.

Refs: #1303
This commit is contained in:
wizardchen
2026-05-18 11:58:46 +08:00
committed by lyingbug
parent 4aedf5fd62
commit 7528175a74
10 changed files with 355 additions and 71 deletions
+15
View File
@@ -319,6 +319,21 @@ CREATE INDEX IF NOT EXISTS idx_user_resource_favorites_user_tenant_type_created_
CREATE INDEX IF NOT EXISTS idx_user_resource_favorites_tenant_id
ON user_resource_favorites(tenant_id);
-- user_kb_pins — sqlite mirror of migration 000050. Per-(user, tenant)
-- pinned knowledge bases; replaces the tenant-wide knowledge_bases.is_pinned
-- column for ordering purposes. The legacy column on knowledge_bases is
-- still defined above for back-compat with existing rows but is no longer
-- written by the application.
CREATE TABLE IF NOT EXISTS user_kb_pins (
tenant_id INTEGER NOT NULL,
user_id VARCHAR(36) NOT NULL,
kb_id VARCHAR(36) NOT NULL,
pinned_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tenant_id, user_id, kb_id)
);
CREATE INDEX IF NOT EXISTS idx_user_kb_pins_user_tenant_pinned_at
ON user_kb_pins(tenant_id, user_id, pinned_at DESC);
-- tenant_invitations — sqlite mirror of migration 000048. SQLite supports
-- partial unique indexes too, so the same "one pending per (tenant,
-- invitee)" guard can be applied verbatim.