whois/template/database/migrate.go

40 lines
589 B
Go
Raw Permalink Normal View History

2025-01-05 19:39:13 -05:00
package database
import (
"log"
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
type Migrator func(*sql.DB) (*sql.DB, error)
func DoNothing(dbConn *sql.DB) (*sql.DB, error) {
log.Println("doing nothing")
_, err := dbConn.Exec(`SELECT 0;`)
if err != nil {
return dbConn, err
}
return dbConn, nil
}
func Migrate(dbConn *sql.DB) (*sql.DB, error) {
log.Println("migrating database")
migrations := []Migrator{
DoNothing,
}
for _, migration := range migrations {
dbConn, err := migration(dbConn)
if err != nil {
return dbConn, err
}
}
return dbConn, nil
}