1
0
forked from MTSR/mapserver
mapserver/mapobjectdb/postgres/migrate.go

35 lines
564 B
Go
Raw Normal View History

2019-03-21 17:07:09 +03:00
package postgres
import (
"database/sql"
2021-04-12 14:03:10 +03:00
"mapserver/public"
2019-03-21 17:07:09 +03:00
"github.com/sirupsen/logrus"
2021-04-12 14:03:10 +03:00
2019-03-21 17:07:09 +03:00
"time"
)
type PostgresAccessor struct {
db *sql.DB
}
func (db *PostgresAccessor) Migrate() error {
log.Info("Migrating database")
start := time.Now()
2021-04-12 14:03:10 +03:00
sql, err := public.Files.ReadFile("sql/postgres_mapobjectdb_migrate.sql")
2019-03-21 17:07:09 +03:00
if err != nil {
return err
}
2021-04-12 14:03:10 +03:00
_, err = db.db.Exec(string(sql))
if err != nil {
return err
}
2019-03-21 17:07:09 +03:00
t := time.Now()
elapsed := t.Sub(start)
log.WithFields(logrus.Fields{"elapsed": elapsed}).Info("Migration completed")
return nil
}