Add metadata and thread_id columns to dependencies table to support: - Edge metadata: JSON blob for type-specific data (similarity scores, etc.) - Thread queries: O(1) conversation threading via thread_id Changes: - New migration 020_edge_consolidation.go - Updated Dependency struct with Metadata and ThreadID fields - Added new entity types: authored-by, assigned-to, approved-by - Relaxed DependencyType validation (any non-empty string ≤50 chars) - Added IsWellKnown() and AffectsReadyWork() methods - Updated SQL queries to include new columns - Updated tests for new behavior This enables HOP knowledge graph requirements and Reddit-style threading. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
// MigrateEdgeConsolidation adds metadata and thread_id columns to the dependencies table.
|
|
// This is Phase 1 of the Edge Schema Consolidation (Decision 004):
|
|
// - metadata: JSON blob for type-specific edge data (similarity scores, reasons, etc.)
|
|
// - thread_id: For efficient conversation threading queries
|
|
//
|
|
// These columns enable:
|
|
// - Edge metadata without schema changes (extensibility)
|
|
// - O(1) thread queries for Reddit-style conversations
|
|
// - HOP knowledge graph foundation
|
|
func MigrateEdgeConsolidation(db *sql.DB) error {
|
|
columns := []struct {
|
|
name string
|
|
definition string
|
|
}{
|
|
{"metadata", "TEXT DEFAULT '{}'"},
|
|
{"thread_id", "TEXT DEFAULT ''"},
|
|
}
|
|
|
|
for _, col := range columns {
|
|
var columnExists bool
|
|
err := db.QueryRow(`
|
|
SELECT COUNT(*) > 0
|
|
FROM pragma_table_info('dependencies')
|
|
WHERE name = ?
|
|
`, col.name).Scan(&columnExists)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to check %s column: %w", col.name, err)
|
|
}
|
|
|
|
if columnExists {
|
|
continue
|
|
}
|
|
|
|
_, err = db.Exec(fmt.Sprintf(`ALTER TABLE dependencies ADD COLUMN %s %s`, col.name, col.definition))
|
|
if err != nil {
|
|
return fmt.Errorf("failed to add %s column: %w", col.name, err)
|
|
}
|
|
}
|
|
|
|
// Add index for thread queries - only index non-empty thread_ids
|
|
_, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_dependencies_thread ON dependencies(thread_id) WHERE thread_id != ''`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create thread_id index: %w", err)
|
|
}
|
|
|
|
// Add composite index for finding all edges in a thread by type
|
|
_, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_dependencies_thread_type ON dependencies(thread_id, type) WHERE thread_id != ''`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create thread_type index: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|