Files
beads/internal/storage/sqlite/migrations/017_close_reason_column.go
Steve Yegge 09fffa4eaf fix(db): add close_reason column to issues table (bd-uyu)
- Add migration 017_close_reason_column.go to create the column
- Update all INSERT statements to include close_reason
- Update all SELECT statements to include close_reason
- Update doctor.go to check for close_reason in schema validation
- Remove workaround code that batch-loaded close reasons from events table
- Fix migrations_test.go to include close_reason in test table schema

This fixes sync loops where close_reason values were silently dropped
because the DB lacked the column despite the struct having the field.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-01 21:56:41 -08:00

32 lines
710 B
Go

package migrations
import (
"database/sql"
"fmt"
)
// MigrateCloseReasonColumn adds the close_reason column to the issues table.
// This column stores the reason provided when closing an issue.
func MigrateCloseReasonColumn(db *sql.DB) error {
var columnExists bool
err := db.QueryRow(`
SELECT COUNT(*) > 0
FROM pragma_table_info('issues')
WHERE name = 'close_reason'
`).Scan(&columnExists)
if err != nil {
return fmt.Errorf("failed to check close_reason column: %w", err)
}
if columnExists {
return nil
}
_, err = db.Exec(`ALTER TABLE issues ADD COLUMN close_reason TEXT DEFAULT ''`)
if err != nil {
return fmt.Errorf("failed to add close_reason column: %w", err)
}
return nil
}