From f69ad01029b78f5cb325b8fc56256b893167a2de Mon Sep 17 00:00:00 2001 From: slothful-vassal <89943360+slothful-vassal@users.noreply.github.com> Date: Wed, 13 May 2026 19:11:01 +0200 Subject: [PATCH] optimize db view queries (#729) * optimize db view queries * add more indices * appease gofmt --------- Co-authored-by: Flomp Co-authored-by: Christian Beutel <> --- ...00200_optimize_trails_bounding_box_view.go | 38 ++++++ .../1770000002_optimize_trails_filter_view.go | 120 ++++++++++++++++++ .../1778583029_updated_activitypub_actors.go | 49 +++++++ .../1778583207_updated_trails_filter.go | 82 ++++++++++++ .../1778583263_updated_trails_bounding_box.go | 82 ++++++++++++ db/migrations/1778583475_updated_trails.go | 46 +++++++ .../1778583593_updated_trail_share.go | 43 +++++++ .../1778583608_updated_list_share.go | 43 +++++++ 8 files changed, 503 insertions(+) create mode 100644 db/migrations/1764000200_optimize_trails_bounding_box_view.go create mode 100644 db/migrations/1770000002_optimize_trails_filter_view.go create mode 100644 db/migrations/1778583029_updated_activitypub_actors.go create mode 100644 db/migrations/1778583207_updated_trails_filter.go create mode 100644 db/migrations/1778583263_updated_trails_bounding_box.go create mode 100644 db/migrations/1778583475_updated_trails.go create mode 100644 db/migrations/1778583593_updated_trail_share.go create mode 100644 db/migrations/1778583608_updated_list_share.go diff --git a/db/migrations/1764000200_optimize_trails_bounding_box_view.go b/db/migrations/1764000200_optimize_trails_bounding_box_view.go new file mode 100644 index 00000000..fdb9552d --- /dev/null +++ b/db/migrations/1764000200_optimize_trails_bounding_box_view.go @@ -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) + }) +} diff --git a/db/migrations/1770000002_optimize_trails_filter_view.go b/db/migrations/1770000002_optimize_trails_filter_view.go new file mode 100644 index 00000000..902332c0 --- /dev/null +++ b/db/migrations/1770000002_optimize_trails_filter_view.go @@ -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) +} diff --git a/db/migrations/1778583029_updated_activitypub_actors.go b/db/migrations/1778583029_updated_activitypub_actors.go new file mode 100644 index 00000000..ace10347 --- /dev/null +++ b/db/migrations/1778583029_updated_activitypub_actors.go @@ -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) + }) +} diff --git a/db/migrations/1778583207_updated_trails_filter.go b/db/migrations/1778583207_updated_trails_filter.go new file mode 100644 index 00000000..17c17997 --- /dev/null +++ b/db/migrations/1778583207_updated_trails_filter.go @@ -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) + }) +} diff --git a/db/migrations/1778583263_updated_trails_bounding_box.go b/db/migrations/1778583263_updated_trails_bounding_box.go new file mode 100644 index 00000000..068e374d --- /dev/null +++ b/db/migrations/1778583263_updated_trails_bounding_box.go @@ -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) + }) +} diff --git a/db/migrations/1778583475_updated_trails.go b/db/migrations/1778583475_updated_trails.go new file mode 100644 index 00000000..05ea4303 --- /dev/null +++ b/db/migrations/1778583475_updated_trails.go @@ -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) + }) +} diff --git a/db/migrations/1778583593_updated_trail_share.go b/db/migrations/1778583593_updated_trail_share.go new file mode 100644 index 00000000..7845a8ac --- /dev/null +++ b/db/migrations/1778583593_updated_trail_share.go @@ -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) + }) +} diff --git a/db/migrations/1778583608_updated_list_share.go b/db/migrations/1778583608_updated_list_share.go new file mode 100644 index 00000000..1418473d --- /dev/null +++ b/db/migrations/1778583608_updated_list_share.go @@ -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) + }) +}