Extract SQLite migrations into separate files (bd-fb95094c.7)
- 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
This commit is contained in:
36
internal/storage/sqlite/migrations/013_repo_mtimes_table.go
Normal file
36
internal/storage/sqlite/migrations/013_repo_mtimes_table.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func MigrateRepoMtimesTable(db *sql.DB) error {
|
||||
var tableName string
|
||||
err := db.QueryRow(`
|
||||
SELECT name FROM sqlite_master
|
||||
WHERE type='table' AND name='repo_mtimes'
|
||||
`).Scan(&tableName)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
_, err := db.Exec(`
|
||||
CREATE TABLE repo_mtimes (
|
||||
repo_path TEXT PRIMARY KEY,
|
||||
jsonl_path TEXT NOT NULL,
|
||||
mtime_ns INTEGER NOT NULL,
|
||||
last_checked DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX idx_repo_mtimes_checked ON repo_mtimes(last_checked);
|
||||
`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create repo_mtimes table: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check for repo_mtimes table: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user