initial commit

This commit is contained in:
ston1th 2019-04-19 15:45:28 +02:00
commit 18995db757
871 changed files with 492725 additions and 0 deletions

48
pkg/db/migration.go Normal file
View file

@ -0,0 +1,48 @@
package db
import (
"git.giftfish.de/ston1th/docstore/pkg/log"
"git.giftfish.de/ston1th/docstore/pkg/store"
)
const (
versionKey = "version/version"
currentVersion = 1
)
type migrator func(*DB) (int, error)
var migrators = []migrator{
func(db *DB) (int, error) {
return 0, nil
},
}
func (db *DB) RunMigrations() (err error) {
var version int
err = db.store.Get(versionKey, &version)
if err == store.ErrKeyNotFound {
err = db.store.Set(versionKey, currentVersion)
if err != nil {
return
}
err = db.store.Get(versionKey, &version)
if err != nil {
return
}
}
log.Printf("db: database version %d", version)
for version < currentVersion {
v := version + 1
log.Printf("db: running migration %d", v)
version, err = migrators[v](db)
if err != nil {
return
}
err = db.store.Set(versionKey, version)
if err != nil {
return
}
}
return
}