fix: PG array format for tags, entity slug prefixes, archive path handling

- knowledge.go: scan tags as []string from pgx (not JSON)
- seed.go: convert tags to PG array format, fix runbook applies_to_type
- convert-wiki.py: fix entity slug prefixes to match inventory.yaml
  (host: not proxmox-host:, ws: not workstation:, service:homelab-mcp with hyphen)
- convert-wiki.py: read from archive/knowledge/ since wiki was archived
This commit is contained in:
2026-07-07 20:37:17 +02:00
parent 6b75f7302d
commit f04e0dc0d4
4 changed files with 493 additions and 494 deletions

View File

@@ -191,6 +191,9 @@ func ingestRunbook(ctx context.Context, tx pgx.Tx, m map[string]any) error {
if riskClass != "" {
attrs["risk_class"] = riskClass
}
if entityType != "" {
attrs["applies_to_type"] = entityType
}
if len(procedure) > 0 {
attrs["procedure"] = procedure
}
@@ -204,12 +207,6 @@ func ingestRunbook(ctx context.Context, tx pgx.Tx, m map[string]any) error {
}
}
if entityType != "" {
if err := createEdge(ctx, tx, entitySlug, entityType, "procedure-for", nil); err != nil {
return fmt.Errorf("link runbook: %w", err)
}
}
return nil
}
@@ -220,7 +217,7 @@ func upsertKnowledgeEntity(ctx context.Context, tx pgx.Tx, slug, entityType, tit
}
hash := contentHash(content)
tagsJSON, _ := json.Marshal(tags)
tagArray := toPGArray(tags)
_, err = tx.Exec(ctx,
`INSERT INTO knowledge_entities (entity_id, title, content, source, tags, content_hash, created_at, updated_at)
@@ -228,7 +225,7 @@ func upsertKnowledgeEntity(ctx context.Context, tx pgx.Tx, slug, entityType, tit
ON CONFLICT (entity_id) DO UPDATE SET
title = $2, content = $3, source = $4, tags = $5,
content_hash = $6, updated_at = now()`,
id, title, content, source, string(tagsJSON), hash)
id, title, content, source, tagArray, hash)
return err
}
@@ -273,4 +270,19 @@ func createEdge(ctx context.Context, tx pgx.Tx, sourceSlug, targetSlug, relType
DO UPDATE SET attributes = EXCLUDED.attributes`,
sourceID, targetID, relType, string(attrsBytes))
return err
}
func toPGArray(tags []string) string {
if len(tags) == 0 {
return "{}"
}
out := "{"
for i, t := range tags {
if i > 0 {
out += ","
}
out += `"` + t + `"`
}
out += "}"
return out
}