diff --git a/migrations/8_dashboardview.go b/migrations/8_dashboardview.go new file mode 100644 index 0000000..b2fdb47 --- /dev/null +++ b/migrations/8_dashboardview.go @@ -0,0 +1,43 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + "github.com/pocketbase/pocketbase/tools/types" +) + +const dashboardCountsViewUpdateQuery = `SELECT id, count FROM ( + SELECT 'users' as id, COUNT(users.id) as count FROM users + UNION + SELECT 'tickets' as id, COUNT(tickets.id) as count FROM tickets + UNION + SELECT 'tasks' as id, COUNT(tasks.id) as count FROM tasks + UNION + SELECT 'reactions' as id, COUNT(reactions.id) as count FROM reactions +) as counts;` + +func dashboardCountsViewUpdateUp(db dbx.Builder) error { + dao := daos.New(db) + + collection, err := dao.FindCollectionByNameOrId(dashboardCountsViewName) + if err != nil { + return err + } + + collection.Options = types.JsonMap{"query": dashboardCountsViewUpdateQuery} + + return dao.SaveCollection(collection) +} + +func dashboardCountsViewUpdateDown(db dbx.Builder) error { + dao := daos.New(db) + + collection, err := dao.FindCollectionByNameOrId(dashboardCountsViewName) + if err != nil { + return err + } + + collection.Options = types.JsonMap{"query": dashboardCountsViewQuery} + + return dao.SaveCollection(collection) +} diff --git a/migrations/migrations.go b/migrations/migrations.go index 7fbedc1..f541468 100644 --- a/migrations/migrations.go +++ b/migrations/migrations.go @@ -12,4 +12,5 @@ func Register() { migrations.Register(reactionsUp, reactionsDown, "1700000005_reactions.go") migrations.Register(systemuserUp, systemuserDown, "1700000006_systemuser.go") migrations.Register(searchViewUp, searchViewDown, "1700000007_search_view.go") + migrations.Register(dashboardCountsViewUpdateUp, dashboardCountsViewUpdateDown, "1700000008_dashboardview.go") } diff --git a/ui/index.html b/ui/index.html index eb40416..de3d68a 100644 --- a/ui/index.html +++ b/ui/index.html @@ -7,7 +7,7 @@