feat(wiki): add page hierarchy/category metadata and retrieval APIs
Persist category and hierarchy metadata on wiki pages (new migration), expose category-path retrieval and related repository/service/handler/router APIs, and update wiki ingestion (batch, cite, taxonomy) plus agent wiki prompts to build and consume the taxonomy. Regenerate swagger docs for the new endpoints.
This commit is contained in:
@@ -22,6 +22,11 @@ CREATE TABLE IF NOT EXISTS wiki_pages (
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'published',
|
||||
content TEXT NOT NULL DEFAULT '',
|
||||
summary TEXT NOT NULL DEFAULT '',
|
||||
parent_slug VARCHAR(255) NOT NULL DEFAULT '',
|
||||
category_path JSONB DEFAULT '[]'::JSONB,
|
||||
wiki_path VARCHAR(1024) NOT NULL DEFAULT '',
|
||||
depth INT NOT NULL DEFAULT 0,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
source_refs JSONB DEFAULT '[]'::JSONB,
|
||||
chunk_refs JSONB DEFAULT '[]'::JSONB,
|
||||
in_links JSONB DEFAULT '[]'::JSONB,
|
||||
@@ -45,6 +50,12 @@ CREATE INDEX IF NOT EXISTS idx_wiki_pages_kb_id
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_page_type
|
||||
ON wiki_pages (knowledge_base_id, page_type);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_parent_slug
|
||||
ON wiki_pages (knowledge_base_id, parent_slug);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_tree
|
||||
ON wiki_pages (knowledge_base_id, page_type, wiki_path, sort_order, title);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_tenant_id
|
||||
ON wiki_pages (tenant_id);
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
-- Migration: 000061_wiki_page_hierarchy (rollback)
|
||||
|
||||
DROP INDEX IF EXISTS idx_wiki_pages_tree;
|
||||
DROP INDEX IF EXISTS idx_wiki_pages_parent_slug;
|
||||
|
||||
ALTER TABLE wiki_pages DROP COLUMN IF EXISTS sort_order;
|
||||
ALTER TABLE wiki_pages DROP COLUMN IF EXISTS depth;
|
||||
ALTER TABLE wiki_pages DROP COLUMN IF EXISTS wiki_path;
|
||||
ALTER TABLE wiki_pages DROP COLUMN IF EXISTS category_path;
|
||||
ALTER TABLE wiki_pages DROP COLUMN IF EXISTS parent_slug;
|
||||
@@ -0,0 +1,29 @@
|
||||
-- Migration: 000061_wiki_page_hierarchy
|
||||
-- Description: Add structured directory hierarchy fields to wiki_pages.
|
||||
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000061] Applying wiki page hierarchy schema'; END $$;
|
||||
|
||||
ALTER TABLE wiki_pages ADD COLUMN IF NOT EXISTS parent_slug VARCHAR(255) NOT NULL DEFAULT '';
|
||||
ALTER TABLE wiki_pages ADD COLUMN IF NOT EXISTS category_path JSONB DEFAULT '[]'::JSONB;
|
||||
ALTER TABLE wiki_pages ADD COLUMN IF NOT EXISTS wiki_path VARCHAR(1024) NOT NULL DEFAULT '';
|
||||
ALTER TABLE wiki_pages ADD COLUMN IF NOT EXISTS depth INT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE wiki_pages ADD COLUMN IF NOT EXISTS sort_order INT NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE wiki_pages
|
||||
SET
|
||||
category_path = COALESCE(category_path, '[]'::JSONB),
|
||||
depth = COALESCE(depth, 0),
|
||||
wiki_path = CASE
|
||||
WHEN COALESCE(wiki_path, '') <> '' THEN wiki_path
|
||||
WHEN page_type IN ('index', 'log') THEN page_type || '/' || COALESCE(NULLIF(title, ''), slug)
|
||||
ELSE page_type || '/' || COALESCE(NULLIF(title, ''), slug)
|
||||
END
|
||||
WHERE wiki_path = '' OR wiki_path IS NULL OR category_path IS NULL OR depth IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_parent_slug
|
||||
ON wiki_pages (knowledge_base_id, parent_slug);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_wiki_pages_tree
|
||||
ON wiki_pages (knowledge_base_id, page_type, wiki_path, sort_order, title);
|
||||
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000061] wiki page hierarchy schema applied successfully'; END $$;
|
||||
Reference in New Issue
Block a user