mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25:32 +00:00
tables for sessions + user settings + editor
This commit is contained in:
55
migrations/1747860355_users.go
Normal file
55
migrations/1747860355_users.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.USERS_TABLE)
|
||||
if err != nil {
|
||||
app.Logger().Error("Failed to find 'users' collection to add 'settings' field", "id", dbmodels.USERS_TABLE, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
settingsField := &core.JSONField{
|
||||
Name: dbmodels.USERS_SETTINGS_FIELD,
|
||||
Required: false,
|
||||
Presentable: false,
|
||||
}
|
||||
|
||||
collection.Fields.Add(settingsField)
|
||||
|
||||
app.Logger().Info("Adding 'settings' JSON field to 'users' collection", "collectionId", collection.Id)
|
||||
|
||||
return app.Save(collection)
|
||||
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId(dbmodels.USERS_TABLE)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not found") || strings.Contains(err.Error(), "no rows in result set") {
|
||||
app.Logger().Warn("Users collection not found during rollback of 'settings' field, assuming already handled.", "id", dbmodels.USERS_TABLE)
|
||||
return nil
|
||||
}
|
||||
app.Logger().Error("Failed to find 'users' collection for 'settings' field rollback", "id", dbmodels.USERS_TABLE, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
collection.Fields.RemoveByName(dbmodels.USERS_SETTINGS_FIELD)
|
||||
if err := app.Save(collection); err != nil {
|
||||
app.Logger().Warn("Failed to remove 'settings' field during rollback (it might not exist)",
|
||||
"collectionId", collection.Id,
|
||||
"field", dbmodels.USERS_SETTINGS_FIELD,
|
||||
"error", err,
|
||||
)
|
||||
} else {
|
||||
app.Logger().Info("Removed 'settings' JSON field from 'users' collection", "collectionId", collection.Id)
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user