From 8be792a4605d74278ab873f040be1167a7c173d8 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Mon, 10 Nov 2025 10:50:13 -0800 Subject: [PATCH] Fix external_ref migration failure on old databases The schema initialization was trying to create an index on the external_ref column before the migration that adds the column runs. This caused 'no such column: external_ref' errors when opening very old databases (pre-0.17.5). Solution: Move the index creation into the migration that adds the column. Fixes #284 Amp-Thread-ID: https://ampcode.com/threads/T-2744d5a7-168f-4ef6-bcab-926db846de20 Co-authored-by: Amp --- .../storage/sqlite/migrations/002_external_ref_column.go | 6 ++++++ internal/storage/sqlite/schema.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/storage/sqlite/migrations/002_external_ref_column.go b/internal/storage/sqlite/migrations/002_external_ref_column.go index e5d2f0c4..fea879e6 100644 --- a/internal/storage/sqlite/migrations/002_external_ref_column.go +++ b/internal/storage/sqlite/migrations/002_external_ref_column.go @@ -39,5 +39,11 @@ func MigrateExternalRefColumn(db *sql.DB) error { } } + // Create index on external_ref (idempotent) + _, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_external_ref ON issues(external_ref)`) + if err != nil { + return fmt.Errorf("failed to create index on external_ref: %w", err) + } + return nil } diff --git a/internal/storage/sqlite/schema.go b/internal/storage/sqlite/schema.go index e54b5894..65f68cfe 100644 --- a/internal/storage/sqlite/schema.go +++ b/internal/storage/sqlite/schema.go @@ -30,7 +30,7 @@ CREATE INDEX IF NOT EXISTS idx_issues_status ON issues(status); CREATE INDEX IF NOT EXISTS idx_issues_priority ON issues(priority); CREATE INDEX IF NOT EXISTS idx_issues_assignee ON issues(assignee); CREATE INDEX IF NOT EXISTS idx_issues_created_at ON issues(created_at); -CREATE INDEX IF NOT EXISTS idx_issues_external_ref ON issues(external_ref); +-- Note: idx_issues_external_ref is created in migrations/002_external_ref_column.go -- Dependencies table CREATE TABLE IF NOT EXISTS dependencies (