1
0
forked from MTSR/mapserver
mapserver/mapobjectdb/sqlite/migrate.go
Buckaroo Banzai be38c83fd8
db cleanup (#341)
* db cleanup

* dev

* pg setup

* postgres uuid migration

* cleanup

* fk

* sqlite migration

* cleanup

* wal

* max open conns = 1

* fix panic

---------

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2023-12-27 10:35:24 +01:00

47 lines
858 B
Go

package sqlite
import (
"database/sql"
"embed"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
"github.com/golang-migrate/migrate/v4/source/iofs"
"github.com/sirupsen/logrus"
_ "modernc.org/sqlite"
)
//go:embed migrations/*.sql
var migrations embed.FS
type Sqlite3Accessor struct {
db *sql.DB
}
func (a *Sqlite3Accessor) Migrate() error {
driver, err := sqlite3.WithInstance(a.db, &sqlite3.Config{})
if err != nil {
return err
}
d, err := iofs.New(migrations, "migrations")
if err != nil {
return err
}
m, err := migrate.NewWithInstance("iofs", d, "sqlite", driver)
if err != nil {
return err
}
err = m.Up()
if err != nil && err != migrate.ErrNoChange {
return err
}
v, _, _ := m.Version()
logrus.WithFields(logrus.Fields{"version": v}).Info("DB Migrated")
return nil
}