Add Pinned field to Issue struct and database schema to protect issues from accidental deletion via cleanup or compaction. Changes: - Add Pinned bool field to types.Issue - Create migration 023_pinned_column.go for database schema - Filter out pinned issues in cleanup command before deletion - Add pinned check to GetTier1Candidates and GetTier2Candidates - Add pinned check to CheckEligibility for compaction - Update all SQL queries and scan functions to include pinned field 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
38 lines
927 B
Go
38 lines
927 B
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
// MigratePinnedColumn adds the pinned column to the issues table.
|
|
// Pinned issues are protected from cleanup and compaction operations (bd-b2k).
|
|
func MigratePinnedColumn(db *sql.DB) error {
|
|
var columnExists bool
|
|
err := db.QueryRow(`
|
|
SELECT COUNT(*) > 0
|
|
FROM pragma_table_info('issues')
|
|
WHERE name = 'pinned'
|
|
`).Scan(&columnExists)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to check pinned column: %w", err)
|
|
}
|
|
|
|
if columnExists {
|
|
return nil
|
|
}
|
|
|
|
_, err = db.Exec(`ALTER TABLE issues ADD COLUMN pinned INTEGER DEFAULT 0`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to add pinned column: %w", err)
|
|
}
|
|
|
|
// Add index for pinned issues (for efficient queries)
|
|
_, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_pinned ON issues(pinned) WHERE pinned = 1`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create pinned index: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|