optimize db view queries (#729)

* optimize db view queries

* add more indices

* appease gofmt

---------

Co-authored-by: Flomp <Flomp@users.noreply.github.com>
Co-authored-by: Christian Beutel <>
This commit is contained in:
slothful-vassal
2026-05-13 19:11:01 +02:00
committed by GitHub
parent 611a7b5f02
commit f69ad01029
8 changed files with 503 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("urytyc428mwlbqq")
if err != nil {
return err
}
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT \n a.id, a.user, \n COALESCE(MAX(t.max_lat), 0) AS max_lat, \n COALESCE(MAX(t.max_lon), 0) AS max_lon, \n COALESCE(MIN(t.min_lat), 0) AS min_lat, \n COALESCE(MIN(t.min_lon), 0) AS min_lon \nFROM activitypub_actors a \nLEFT JOIN ( \n SELECT author AS actor_id, \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n GROUP BY author \n UNION ALL \n SELECT ts.actor AS actor_id, \n MAX(t.lat) AS max_lat, \n MAX(t.lon) AS max_lon, \n MIN(t.lat) AS min_lat, \n MIN(t.lon) AS min_lon \n FROM trail_share ts \n JOIN trails t ON t.id = ts.trail \n GROUP BY ts.actor \n UNION ALL \n SELECT a2.id AS actor_id, \n p.max_lat, p.max_lon, p.min_lat, p.min_lon \n FROM activitypub_actors a2 \n CROSS JOIN ( \n SELECT \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n WHERE public = TRUE \n ) p \n) t ON t.actor_id = a.id \nGROUP BY a.id;"
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("urytyc428mwlbqq")
if err != nil {
return err
}
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT \n activitypub_actors.id, activitypub_actors.user, \n COALESCE(MAX(trails.lat), 0) AS max_lat, \n COALESCE(MAX(trails.lon), 0) AS max_lon, \n COALESCE(MIN(trails.lat), 0) AS min_lat, \n COALESCE(MIN(trails.lon), 0) AS min_lon \nFROM activitypub_actors \nLEFT JOIN trails \n ON activitypub_actors.id = trails.author \n OR trails.public = TRUE \n OR EXISTS (\n SELECT 1 \n FROM trail_share \n WHERE trail_share.trail = trails.id \n AND trail_share.actor = activitypub_actors.id\n ) \nGROUP BY activitypub_actors.id;"
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -0,0 +1,120 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("trails_filter")
if err != nil {
return err
}
viewQuery := `SELECT
a.id,
a.user,
COALESCE(printf("%.2f", MAX(t.max_distance)), 0) AS max_distance,
COALESCE(printf("%.2f", MAX(t.max_elevation_gain)), 0) AS max_elevation_gain,
COALESCE(printf("%.2f", MAX(t.max_elevation_loss)), 0) AS max_elevation_loss,
COALESCE(printf("%.2f", MAX(t.max_duration)), 0) AS max_duration,
COALESCE(printf("%.2f", MIN(t.min_distance)), 0) AS min_distance,
COALESCE(printf("%.2f", MIN(t.min_elevation_gain)), 0) AS min_elevation_gain,
COALESCE(printf("%.2f", MIN(t.min_elevation_loss)), 0) AS min_elevation_loss,
COALESCE(printf("%.2f", MIN(t.min_duration)), 0) AS min_duration
FROM activitypub_actors a
LEFT JOIN (
SELECT author AS actor_id,
MAX(distance) AS max_distance,
MIN(distance) AS min_distance,
MAX(elevation_gain) AS max_elevation_gain,
MIN(elevation_gain) AS min_elevation_gain,
MAX(elevation_loss) AS max_elevation_loss,
MIN(elevation_loss) AS min_elevation_loss,
MAX(duration) AS max_duration,
MIN(duration) AS min_duration
FROM trails
GROUP BY author
UNION ALL
SELECT ts.actor AS actor_id,
MAX(t.distance) AS max_distance,
MIN(t.distance) AS min_distance,
MAX(t.elevation_gain) AS max_elevation_gain,
MIN(t.elevation_gain) AS min_elevation_gain,
MAX(t.elevation_loss) AS max_elevation_loss,
MIN(t.elevation_loss) AS min_elevation_loss,
MAX(t.duration) AS max_duration,
MIN(t.duration) AS min_duration
FROM trail_share ts
JOIN trails t ON t.id = ts.trail
GROUP BY ts.actor
UNION ALL
SELECT a2.id AS actor_id,
p.max_distance,
p.min_distance,
p.max_elevation_gain,
p.min_elevation_gain,
p.max_elevation_loss,
p.min_elevation_loss,
p.max_duration,
p.min_duration
FROM activitypub_actors a2
CROSS JOIN (
SELECT
MAX(distance) AS max_distance,
MIN(distance) AS min_distance,
MAX(elevation_gain) AS max_elevation_gain,
MIN(elevation_gain) AS min_elevation_gain,
MAX(elevation_loss) AS max_elevation_loss,
MIN(elevation_loss) AS min_elevation_loss,
MAX(duration) AS max_duration,
MIN(duration) AS min_duration
FROM trails
WHERE public = TRUE
) p
) t ON t.actor_id = a.id
GROUP BY a.id;`
if err := json.Unmarshal([]byte(`{"viewQuery": `+jsonMarshal(viewQuery)+`}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("trails_filter")
if err != nil {
return err
}
viewQuery := `SELECT activitypub_actors.id, activitypub_actors.user, COALESCE(printf("%.2f", MAX(trails.distance)), 0) AS max_distance,
COALESCE(printf("%.2f", MAX(trails.elevation_gain)), 0) AS max_elevation_gain,
COALESCE(printf("%.2f", MAX(trails.elevation_loss)), 0) AS max_elevation_loss,
COALESCE(printf("%.2f", MAX(trails.duration)), 0) AS max_duration,
COALESCE(printf("%.2f", MIN(trails.distance)), 0) AS min_distance,
COALESCE(printf("%.2f", MIN(trails.elevation_gain)), 0) AS min_elevation_gain,
COALESCE(printf("%.2f", MIN(trails.elevation_loss)), 0) AS min_elevation_loss,
COALESCE(printf("%.2f", MIN(trails.duration)), 0) AS min_duration
FROM activitypub_actors
LEFT JOIN trails ON
activitypub_actors.id = trails.author OR
trails.public = 1 OR
EXISTS (
SELECT 1
FROM trail_share
WHERE trail_share.trail = trails.id
AND trail_share.actor = activitypub_actors.id
) GROUP BY activitypub_actors.id;`
if err := json.Unmarshal([]byte(`{"viewQuery": `+jsonMarshal(viewQuery)+`}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}
func jsonMarshal(value string) string {
b, _ := json.Marshal(value)
return string(b)
}

View File

@@ -0,0 +1,49 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("pbc_1295301207")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE UNIQUE INDEX `+"`"+`idx_rpT7QJwWTm`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (`+"`"+`iri`+"`"+`)",
"CREATE UNIQUE INDEX `+"`"+`idx_actors_username_domain`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (\n `+"`"+`preferred_username`+"`"+`,\n `+"`"+`domain`+"`"+`\n)",
"CREATE INDEX idx_activitypub_actors_user ON activitypub_actors(user) WHERE user IS NOT null;",
"CREATE INDEX `+"`"+`idx_x8xyfe8q8y`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (`+"`"+`inbox`+"`"+`)"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("pbc_1295301207")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE UNIQUE INDEX `+"`"+`idx_rpT7QJwWTm`+"`"+` ON `+"`"+`activitypub_actors`+"`"+` (`+"`"+`iri`+"`"+`)",
"CREATE INDEX idx_actors_username_domain\nON activitypub_actors(preferred_username, domain);",
"CREATE INDEX idx_activitypub_actors_user ON activitypub_actors(user);"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -0,0 +1,82 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT\n a.id,\n a.user,\n COALESCE(printf(\"%.2f\", MAX(t.max_distance)), 0) AS max_distance,\n COALESCE(printf(\"%.2f\", MAX(t.max_elevation_gain)), 0) AS max_elevation_gain,\n COALESCE(printf(\"%.2f\", MAX(t.max_elevation_loss)), 0) AS max_elevation_loss,\n COALESCE(printf(\"%.2f\", MAX(t.max_duration)), 0) AS max_duration,\n COALESCE(printf(\"%.2f\", MIN(t.min_distance)), 0) AS min_distance,\n COALESCE(printf(\"%.2f\", MIN(t.min_elevation_gain)), 0) AS min_elevation_gain,\n COALESCE(printf(\"%.2f\", MIN(t.min_elevation_loss)), 0) AS min_elevation_loss,\n COALESCE(printf(\"%.2f\", MIN(t.min_duration)), 0) AS min_duration\nFROM activitypub_actors a\nLEFT JOIN (\n SELECT author AS actor_id,\n MAX(distance) AS max_distance,\n MIN(distance) AS min_distance,\n MAX(elevation_gain) AS max_elevation_gain,\n MIN(elevation_gain) AS min_elevation_gain,\n MAX(elevation_loss) AS max_elevation_loss,\n MIN(elevation_loss) AS min_elevation_loss,\n MAX(duration) AS max_duration,\n MIN(duration) AS min_duration\n FROM trails\n GROUP BY author\n UNION ALL\n SELECT ts.actor AS actor_id,\n MAX(t.distance) AS max_distance,\n MIN(t.distance) AS min_distance,\n MAX(t.elevation_gain) AS max_elevation_gain,\n MIN(t.elevation_gain) AS min_elevation_gain,\n MAX(t.elevation_loss) AS max_elevation_loss,\n MIN(t.elevation_loss) AS min_elevation_loss,\n MAX(t.duration) AS max_duration,\n MIN(t.duration) AS min_duration\n FROM trail_share ts\n JOIN trails t ON t.id = ts.trail\n GROUP BY ts.actor\n UNION ALL\n SELECT a2.id AS actor_id,\n p.max_distance,\n p.min_distance,\n p.max_elevation_gain,\n p.min_elevation_gain,\n p.max_elevation_loss,\n p.min_elevation_loss,\n p.max_duration,\n p.min_duration\n FROM activitypub_actors a2\n CROSS JOIN (\n SELECT\n MAX(distance) AS max_distance,\n MIN(distance) AS min_distance,\n MAX(elevation_gain) AS max_elevation_gain,\n MIN(elevation_gain) AS min_elevation_gain,\n MAX(elevation_loss) AS max_elevation_loss,\n MIN(elevation_loss) AS min_elevation_loss,\n MAX(duration) AS max_duration,\n MIN(duration) AS min_duration\n FROM trails\n WHERE public = TRUE\n ) p\n) t ON t.actor_id = a.id\nWHERE a.user != \"\"\nGROUP BY a.id;"
}`), &collection); err != nil {
return err
}
// remove field
collection.Fields.RemoveById("_clone_rQGp")
// add field
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"help": "",
"hidden": false,
"id": "_clone_bYSp",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
}`)); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT\n a.id,\n a.user,\n COALESCE(printf(\"%.2f\", MAX(t.max_distance)), 0) AS max_distance,\n COALESCE(printf(\"%.2f\", MAX(t.max_elevation_gain)), 0) AS max_elevation_gain,\n COALESCE(printf(\"%.2f\", MAX(t.max_elevation_loss)), 0) AS max_elevation_loss,\n COALESCE(printf(\"%.2f\", MAX(t.max_duration)), 0) AS max_duration,\n COALESCE(printf(\"%.2f\", MIN(t.min_distance)), 0) AS min_distance,\n COALESCE(printf(\"%.2f\", MIN(t.min_elevation_gain)), 0) AS min_elevation_gain,\n COALESCE(printf(\"%.2f\", MIN(t.min_elevation_loss)), 0) AS min_elevation_loss,\n COALESCE(printf(\"%.2f\", MIN(t.min_duration)), 0) AS min_duration\nFROM activitypub_actors a\nLEFT JOIN (\n SELECT author AS actor_id,\n MAX(distance) AS max_distance,\n MIN(distance) AS min_distance,\n MAX(elevation_gain) AS max_elevation_gain,\n MIN(elevation_gain) AS min_elevation_gain,\n MAX(elevation_loss) AS max_elevation_loss,\n MIN(elevation_loss) AS min_elevation_loss,\n MAX(duration) AS max_duration,\n MIN(duration) AS min_duration\n FROM trails\n GROUP BY author\n UNION ALL\n SELECT ts.actor AS actor_id,\n MAX(t.distance) AS max_distance,\n MIN(t.distance) AS min_distance,\n MAX(t.elevation_gain) AS max_elevation_gain,\n MIN(t.elevation_gain) AS min_elevation_gain,\n MAX(t.elevation_loss) AS max_elevation_loss,\n MIN(t.elevation_loss) AS min_elevation_loss,\n MAX(t.duration) AS max_duration,\n MIN(t.duration) AS min_duration\n FROM trail_share ts\n JOIN trails t ON t.id = ts.trail\n GROUP BY ts.actor\n UNION ALL\n SELECT a2.id AS actor_id,\n p.max_distance,\n p.min_distance,\n p.max_elevation_gain,\n p.min_elevation_gain,\n p.max_elevation_loss,\n p.min_elevation_loss,\n p.max_duration,\n p.min_duration\n FROM activitypub_actors a2\n CROSS JOIN (\n SELECT\n MAX(distance) AS max_distance,\n MIN(distance) AS min_distance,\n MAX(elevation_gain) AS max_elevation_gain,\n MIN(elevation_gain) AS min_elevation_gain,\n MAX(elevation_loss) AS max_elevation_loss,\n MIN(elevation_loss) AS min_elevation_loss,\n MAX(duration) AS max_duration,\n MIN(duration) AS min_duration\n FROM trails\n WHERE public = TRUE\n ) p\n) t ON t.actor_id = a.id\nWHERE a.user is not null\nGROUP BY a.id;"
}`), &collection); err != nil {
return err
}
// add field
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"help": "",
"hidden": false,
"id": "_clone_rQGp",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
}`)); err != nil {
return err
}
// remove field
collection.Fields.RemoveById("_clone_bYSp")
return app.Save(collection)
})
}

View File

@@ -0,0 +1,82 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("urytyc428mwlbqq")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT \n a.id, a.user, \n COALESCE(MAX(t.max_lat), 0) AS max_lat, \n COALESCE(MAX(t.max_lon), 0) AS max_lon, \n COALESCE(MIN(t.min_lat), 0) AS min_lat, \n COALESCE(MIN(t.min_lon), 0) AS min_lon \nFROM activitypub_actors a \nLEFT JOIN ( \n SELECT author AS actor_id, \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n GROUP BY author \n UNION ALL \n SELECT ts.actor AS actor_id, \n MAX(t.lat) AS max_lat, \n MAX(t.lon) AS max_lon, \n MIN(t.lat) AS min_lat, \n MIN(t.lon) AS min_lon \n FROM trail_share ts \n JOIN trails t ON t.id = ts.trail \n GROUP BY ts.actor \n UNION ALL \n SELECT a2.id AS actor_id, \n p.max_lat, p.max_lon, p.min_lat, p.min_lon \n FROM activitypub_actors a2 \n CROSS JOIN ( \n SELECT \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n WHERE public = TRUE \n ) p \n) t ON t.actor_id = a.id \nWHERE a.user != \"\"\nGROUP BY a.id;"
}`), &collection); err != nil {
return err
}
// remove field
collection.Fields.RemoveById("_clone_MXPc")
// add field
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"help": "",
"hidden": false,
"id": "_clone_b2Wa",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
}`)); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("urytyc428mwlbqq")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"viewQuery": "SELECT \n a.id, a.user, \n COALESCE(MAX(t.max_lat), 0) AS max_lat, \n COALESCE(MAX(t.max_lon), 0) AS max_lon, \n COALESCE(MIN(t.min_lat), 0) AS min_lat, \n COALESCE(MIN(t.min_lon), 0) AS min_lon \nFROM activitypub_actors a \nLEFT JOIN ( \n SELECT author AS actor_id, \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n GROUP BY author \n UNION ALL \n SELECT ts.actor AS actor_id, \n MAX(t.lat) AS max_lat, \n MAX(t.lon) AS max_lon, \n MIN(t.lat) AS min_lat, \n MIN(t.lon) AS min_lon \n FROM trail_share ts \n JOIN trails t ON t.id = ts.trail \n GROUP BY ts.actor \n UNION ALL \n SELECT a2.id AS actor_id, \n p.max_lat, p.max_lon, p.min_lat, p.min_lon \n FROM activitypub_actors a2 \n CROSS JOIN ( \n SELECT \n MAX(lat) AS max_lat, \n MAX(lon) AS max_lon, \n MIN(lat) AS min_lat, \n MIN(lon) AS min_lon \n FROM trails \n WHERE public = TRUE \n ) p \n) t ON t.actor_id = a.id \nGROUP BY a.id;"
}`), &collection); err != nil {
return err
}
// add field
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
"cascadeDelete": true,
"collectionId": "_pb_users_auth_",
"help": "",
"hidden": false,
"id": "_clone_MXPc",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
}`)); err != nil {
return err
}
// remove field
collection.Fields.RemoveById("_clone_b2Wa")
return app.Save(collection)
})
}

View File

@@ -0,0 +1,46 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE UNIQUE INDEX `+"`"+`idx_6tD5RqfVk2`+"`"+` ON `+"`"+`trails`+"`"+` (`+"`"+`iri`+"`"+`) WHERE iri IS NOT NULL AND iri != \"\";",
"CREATE INDEX `+"`"+`idx_q2th4tvqqa`+"`"+` ON `+"`"+`trails`+"`"+` (`+"`"+`author`+"`"+`)",
"CREATE INDEX idx_trails_public ON trails (public) WHERE public = true;"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE UNIQUE INDEX `+"`"+`idx_6tD5RqfVk2`+"`"+` ON `+"`"+`trails`+"`"+` (`+"`"+`iri`+"`"+`) WHERE iri IS NOT NULL AND iri != \"\";"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -0,0 +1,43 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("1mns8mlal6uf9ku")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE INDEX idx_trail_share_actor ON trail_share (actor);",
"CREATE INDEX `+"`"+`idx_wd9il80bpf`+"`"+` ON `+"`"+`trail_share`+"`"+` (`+"`"+`trail`+"`"+`)"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("1mns8mlal6uf9ku")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": []
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -0,0 +1,43 @@
package migrations
import (
"encoding/json"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("1kot7t9na3hi0gl")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": [
"CREATE INDEX `+"`"+`idx_rfc8s4r53e`+"`"+` ON `+"`"+`list_share`+"`"+` (`+"`"+`actor`+"`"+`)",
"CREATE INDEX `+"`"+`idx_t2ggivugt5`+"`"+` ON `+"`"+`list_share`+"`"+` (`+"`"+`list`+"`"+`)"
]
}`), &collection); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("1kot7t9na3hi0gl")
if err != nil {
return err
}
// update collection data
if err := json.Unmarshal([]byte(`{
"indexes": []
}`), &collection); err != nil {
return err
}
return app.Save(collection)
})
}