mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 09:38:49 +02:00
feat:#16 added migration for feeds with uuid
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.20.5-alpine
|
FROM golang:1.21.3-alpine
|
||||||
|
|
||||||
# Set the Current Working Directory inside the container
|
# Set the Current Working Directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -27,3 +27,10 @@ type FeedCollection struct {
|
|||||||
Course string `db:"course" json:"course"`
|
Course string `db:"course" json:"course"`
|
||||||
UserDefinedName string `db:"userDefinedName" json:"userDefinedName"`
|
UserDefinedName string `db:"userDefinedName" json:"userDefinedName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UUIDFeedCollection struct {
|
||||||
|
UUID string `db:"uuid" json:"uuid"`
|
||||||
|
Name string `db:"Name" json:"name"`
|
||||||
|
Course string `db:"course" json:"course"`
|
||||||
|
UserDefinedName string `db:"userDefinedName" json:"userDefinedName"`
|
||||||
|
}
|
||||||
|
@ -243,4 +243,22 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||||
|
_, err := e.Router.AddRoute(echo.Route{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/feed/migrate",
|
||||||
|
Handler: func(c echo.Context) error {
|
||||||
|
ical.MigrateFeedJson(app)
|
||||||
|
return c.JSON(200, "Migrated")
|
||||||
|
},
|
||||||
|
Middlewares: []echo.MiddlewareFunc{
|
||||||
|
apis.ActivityLogger(app),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
54
backend/service/ical/icalJsonMigrate.go
Normal file
54
backend/service/ical/icalJsonMigrate.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package ical
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/pocketbase/dbx"
|
||||||
|
"github.com/pocketbase/pocketbase"
|
||||||
|
"htwkalender/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
//update ical feed json
|
||||||
|
//add uuid field
|
||||||
|
//remove module name field
|
||||||
|
|
||||||
|
func MigrateFeedJson(app *pocketbase.PocketBase) {
|
||||||
|
|
||||||
|
var feeds []model.Feed
|
||||||
|
|
||||||
|
err := app.Dao().DB().Select("*").From("feed").All(&feeds)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, feed := range feeds {
|
||||||
|
|
||||||
|
var modules []model.FeedCollection
|
||||||
|
|
||||||
|
err := json.Unmarshal([]byte(feed.Modules), &modules)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var uuidFeedCollection model.UUIDFeedCollection
|
||||||
|
|
||||||
|
for _, module := range modules {
|
||||||
|
uuid := searchUUIDForModule(app, module.Name)
|
||||||
|
|
||||||
|
if uuid != "" {
|
||||||
|
uuidFeedCollection = model.UUIDFeedCollection{UUID: uuid, Name: module.Name, Course: module.Course, UserDefinedName: module.UserDefinedName}
|
||||||
|
app.Dao().DB().Update("feed", dbx.Params{"modules": uuidFeedCollection}, dbx.NewExp("id = {:id}", dbx.Params{"id": feed.Id}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchUUIDForModule(app *pocketbase.PocketBase, module string) string {
|
||||||
|
var uuid string
|
||||||
|
err := app.Dao().DB().Select("uuid").From("module").Where(dbx.NewExp("name = {:name}", dbx.Params{"name": module})).One(&uuid)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return uuid
|
||||||
|
}
|
Reference in New Issue
Block a user