embed_tern/main.go

37 lines
699 B
Go
Raw Normal View History

2023-03-05 09:08:01 +10:30
package main
import (
"embed_tern/migrations"
"os"
)
func main() {
2023-03-05 09:18:47 +10:30
// create a migrator, connecting to the postgresql
// database defined by the environment variable
2023-03-05 09:08:01 +10:30
migrator, err := migrations.NewMigrator(os.Getenv("DB_DNS"))
if err != nil {
panic(err)
}
2023-03-05 09:18:47 +10:30
// get the current migration status
2023-03-05 09:08:01 +10:30
now, exp, info, err := migrator.Info()
if err != nil {
panic(err)
}
if now < exp {
2023-03-05 09:18:47 +10:30
// migration is required, dump out the current state
// and perform the migration
2023-03-05 09:08:01 +10:30
println("migration needed, current state:")
println(info)
err = migrator.Migrate()
if err != nil {
panic(err)
}
println("migration successful!")
} else {
println("no database migration needed")
}
}