2023-07-17 12:48:36 +01:00
|
|
|
package dbAccess
|
|
|
|
|
|
|
|
import (
|
2023-07-19 21:31:00 +01:00
|
|
|
"context"
|
2023-07-18 00:25:13 +01:00
|
|
|
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
2024-03-25 11:26:07 +00:00
|
|
|
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
|
|
|
"git.fjla.uk/owlboard/timetable-mgr/log"
|
2023-07-19 21:31:00 +01:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
2023-07-17 12:48:36 +01:00
|
|
|
)
|
|
|
|
|
2024-03-29 14:01:57 +00:00
|
|
|
// Pushes the current version of this application to the data base 'versions' collection.
|
2024-03-25 12:21:59 +00:00
|
|
|
func PushVersionToDb() {
|
2023-07-19 21:31:00 +01:00
|
|
|
version := database.Version{
|
2024-04-10 20:46:20 +01:00
|
|
|
Target: "timetable-mgr",
|
|
|
|
Component: "timetable-mgr",
|
2023-07-19 21:31:00 +01:00
|
|
|
Version: helpers.Version,
|
|
|
|
}
|
|
|
|
versionSelector := database.VersionSelector{
|
2024-04-10 20:46:20 +01:00
|
|
|
Target: "timetable-mgr",
|
|
|
|
Component: "timetable-mgr",
|
2023-07-19 21:31:00 +01:00
|
|
|
}
|
|
|
|
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 {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Warn("Unable to push version to database: " + err.Error())
|
2023-07-19 21:31:00 +01:00
|
|
|
} else {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Debug("Version up to date in Database")
|
2023-07-19 21:31:00 +01:00
|
|
|
}
|
2023-07-17 12:48:36 +01:00
|
|
|
}
|