Files
beads/internal/storage/sqlite/migrations/033_event_fields.go
Steve Yegge 6d292f6a0f feat: add type: event for operational state changes (bd-ecmd)
Adds support for event beads that capture operational state transitions
as immutable records. Events are a new issue type with fields:
- event_kind: namespaced category (patrol.muted, agent.started)
- actor: entity URI who caused the event
- target: entity URI or bead ID affected
- payload: event-specific JSON data

This enables:
- bd activity --follow showing events
- bd list --type=event --target=agent:deacon
- Full audit trail for operational state
- HOP-compatible transaction records

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/dave
Rig: beads
Role: crew
2025-12-30 15:54:51 -08:00

51 lines
1.2 KiB
Go

package migrations
import (
"database/sql"
"fmt"
)
// MigrateEventFields adds event-specific fields to the issues table.
// These fields support type: event beads for operational state changes.
// Fields:
// - event_kind: namespaced event type (e.g., patrol.muted, agent.started)
// - actor: entity URI who caused this event
// - target: entity URI or bead ID affected
// - payload: event-specific JSON data
func MigrateEventFields(db *sql.DB) error {
columns := []struct {
name string
def string
}{
{"event_kind", "TEXT DEFAULT ''"},
{"actor", "TEXT DEFAULT ''"},
{"target", "TEXT DEFAULT ''"},
{"payload", "TEXT DEFAULT ''"},
}
for _, col := range columns {
// Check if column already exists
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
}
// Add the column
_, err = db.Exec(fmt.Sprintf(`ALTER TABLE issues ADD COLUMN %s %s`, col.name, col.def))
if err != nil {
return fmt.Errorf("failed to add %s column: %w", col.name, err)
}
}
return nil
}