whois/database/migrate.go
Elizabeth Hunt d25ec27fb1
Some checks failed
continuous-integration/drone/push Build is failing
initial commit by simponic-infra
2025-01-05 16:39:13 -08:00

47 lines
843 B
Go

package database
import (
"log"
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
type Migrator func(*sql.DB) (*sql.DB, error)
func AddWhoisUpdates(dbConn *sql.DB) (*sql.DB, error) {
_, err := dbConn.Exec(`CREATE TABLE IF NOT EXISTS updates (
name TEXT,
time TIMESTAMP
);`)
if err != nil {
return dbConn, err
}
log.Println("creating time index on updates table")
_, err = dbConn.Exec(`CREATE INDEX IF NOT EXISTS idx_update_timestamp ON updates (time);`)
if err != nil {
return dbConn, err
}
return dbConn, nil
}
func Migrate(dbConn *sql.DB) (*sql.DB, error) {
log.Println("migrating database")
migrations := []Migrator{
AddWhoisUpdates,
}
for _, migration := range migrations {
dbConn, err := migration(dbConn)
if err != nil {
return dbConn, err
}
}
return dbConn, nil
}