You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
flux-feed/cmd/migrate/main.go

41 lines
934 B
Go

// Entry point for applying database migrations for flux-feed application
package main
import (
"database/sql"
"log"
"git.runcible.io/androiddrew/flux-feed/config"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/mattn/go-sqlite3"
)
func main() {
cfg := config.New()
db, err := sql.Open(cfg.DatabaseDriver, cfg.DatabaseDSN)
defer db.Close()
err = db.Ping()
if err != nil {
log.Fatal(err)
}
log.Printf("Connected to Database: %s", cfg.DatabaseDSN)
driver, err := sqlite3.WithInstance(db, &sqlite3.Config{})
log.Printf("Using migrations path: %s", cfg.MigrationsPath)
m, err := migrate.NewWithDatabaseInstance(
cfg.MigrationsPath, cfg.DatabaseDriver, driver)
if err != nil {
log.Fatal(err)
}
log.Printf("Migrating: %s", cfg.DatabaseDSN)
err = m.Up()
if err != nil {
log.Fatal(err)
}
}