33 lines
944 B
Go
33 lines
944 B
Go
package dbAccess
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
|
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
|
"git.fjla.uk/owlboard/timetable-mgr/log"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// Pushes the current version of this application to the data base 'versions' collection.
|
|
func PushVersionToDb() {
|
|
version := database.Version{
|
|
Target: "timetable-mgr",
|
|
Component: "timetable-mgr",
|
|
Version: helpers.Version,
|
|
}
|
|
versionSelector := database.VersionSelector{
|
|
Target: "timetable-mgr",
|
|
Component: "timetable-mgr",
|
|
}
|
|
opts := options.Update().SetUpsert(true)
|
|
coll := MongoClient.Database("owlboard").Collection("versions")
|
|
_, err := coll.UpdateOne(context.TODO(), versionSelector, bson.M{"$set": version}, opts)
|
|
if err != nil {
|
|
log.Warn("Unable to push version to database: " + err.Error())
|
|
} else {
|
|
log.Debug("Version up to date in Database")
|
|
}
|
|
}
|