1
0
forked from MTSR/mapserver
mapserver/mapobjectdb/sqlite/migrate.go
Buckaroo Banzai ddb5267a3b
Go releaser (#238)
* add goreleaser config

* update go.mod / gitignore

* dev/cross cleanup

* switch to cgo-less sqlite driver

* workflows

* fix build workflow

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2022-02-01 14:59:29 +01:00

49 lines
962 B
Go

package sqlite
import (
"database/sql"
"mapserver/public"
"time"
"github.com/sirupsen/logrus"
_ "modernc.org/sqlite"
)
type Sqlite3Accessor struct {
db *sql.DB
filename string
}
func (db *Sqlite3Accessor) Migrate() error {
log.WithFields(logrus.Fields{"filename": db.filename}).Info("Migrating database")
start := time.Now()
sql, err := public.Files.ReadFile("sql/sqlite_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
}
func (db *Sqlite3Accessor) EnableSpeedSafetyTradeoff(enableSpeed bool) error {
if enableSpeed {
_, err := db.db.Exec("PRAGMA journal_mode = MEMORY; PRAGMA synchronous = OFF;")
return err
} else {
_, err := db.db.Exec("PRAGMA journal_mode = TRUNCATE; PRAGMA synchronous = ON;")
return err
}
}