Files
beads/internal/storage/sqlite/migrations/019_messaging_fields.go
Steve Yegge 0aea2d93c6 feat(schema): add messaging fields for bd-kwro epic
- Add TypeMessage issue type for inter-agent communication
- Add 6 new Issue fields: Sender, Ephemeral, RepliesTo, RelatesTo,
  DuplicateOf, SupersededBy
- Add 4 new dependency types: replies-to, relates-to, duplicates, supersedes
- Create migration 019_messaging_fields with indexes
- Update all CRUD operations across storage layer
- Fix reset_test.go to use correct function names
- Fix redundant newline lint error in sync.go

Closes: bd-kwro.1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 13:06:47 -08:00

70 lines
2.1 KiB
Go

package migrations
import (
"database/sql"
"fmt"
)
// MigrateMessagingFields adds messaging and graph link support columns to the issues table.
// These columns support inter-agent communication (bd-kwro):
// - sender: who sent this message
// - ephemeral: can be bulk-deleted when closed
// - replies_to: issue ID for conversation threading
// - relates_to: JSON array of issue IDs for knowledge graph edges
// - duplicate_of: canonical issue ID (this is a duplicate)
// - superseded_by: replacement issue ID (this is obsolete)
func MigrateMessagingFields(db *sql.DB) error {
columns := []struct {
name string
definition string
}{
{"sender", "TEXT DEFAULT ''"},
{"ephemeral", "INTEGER DEFAULT 0"},
{"replies_to", "TEXT DEFAULT ''"},
{"relates_to", "TEXT DEFAULT ''"},
{"duplicate_of", "TEXT DEFAULT ''"},
{"superseded_by", "TEXT DEFAULT ''"},
}
for _, col := range columns {
var columnExists bool
err := db.QueryRow(`
SELECT COUNT(*) > 0
FROM pragma_table_info('issues')
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 issues 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 ephemeral issues (for efficient cleanup queries)
_, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_ephemeral ON issues(ephemeral) WHERE ephemeral = 1`)
if err != nil {
return fmt.Errorf("failed to create ephemeral index: %w", err)
}
// Add index for sender (for efficient inbox queries)
_, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_sender ON issues(sender) WHERE sender != ''`)
if err != nil {
return fmt.Errorf("failed to create sender index: %w", err)
}
// Add index for replies_to (for efficient thread queries)
_, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_replies_to ON issues(replies_to) WHERE replies_to != ''`)
if err != nil {
return fmt.Errorf("failed to create replies_to index: %w", err)
}
return nil
}