- Created migrations/ subdirectory with 14 individual migration files - Reduced migrations.go from 680 to 98 lines (orchestration only) - Updated test imports to use migrations package - Updated MULTI_REPO_HYDRATION.md documentation - All tests passing
35 lines
745 B
Go
35 lines
745 B
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
func MigrateSourceRepoColumn(db *sql.DB) error {
|
|
var columnExists bool
|
|
err := db.QueryRow(`
|
|
SELECT COUNT(*) > 0
|
|
FROM pragma_table_info('issues')
|
|
WHERE name = 'source_repo'
|
|
`).Scan(&columnExists)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to check source_repo column: %w", err)
|
|
}
|
|
|
|
if columnExists {
|
|
return nil
|
|
}
|
|
|
|
_, err = db.Exec(`ALTER TABLE issues ADD COLUMN source_repo TEXT DEFAULT '.'`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to add source_repo column: %w", err)
|
|
}
|
|
|
|
_, err = db.Exec(`CREATE INDEX IF NOT EXISTS idx_issues_source_repo ON issues(source_repo)`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create source_repo index: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|