mapserver/mapobjectdb/postgres/migrate.go
2021-04-12 13:03:10 +02:00

35 lines
564 B
Go

package postgres
import (
"database/sql"
"mapserver/public"
"github.com/sirupsen/logrus"
"time"
)
type PostgresAccessor struct {
db *sql.DB
}
func (db *PostgresAccessor) Migrate() error {
log.Info("Migrating database")
start := time.Now()
sql, err := public.Files.ReadFile("sql/postgres_mapobjectdb_migrate.sql")
if err != nil {
return err
}
_, err = db.db.Exec(string(sql))
if err != nil {
return err
}
t := time.Now()
elapsed := t.Sub(start)
log.WithFields(logrus.Fields{"elapsed": elapsed}).Info("Migration completed")
return nil
}