badges improvements

This commit is contained in:
2026-08-23 20:31:44 -07:00
parent ac2e61731c
commit e3fea18ab2
9 changed files with 366 additions and 76 deletions
@@ -0,0 +1,36 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
// Dedupe before adding the unique index: keep the best row per
// (player, badge) — earned first, then highest progress, then newest.
app.db().newQuery(`
DELETE FROM badge_progress
WHERE id NOT IN (
SELECT id FROM (
SELECT id, ROW_NUMBER() OVER (
PARTITION BY player, badge
ORDER BY earned DESC, progress DESC, updated DESC
) AS rn
FROM badge_progress
)
WHERE rn = 1
)
`).execute()
const collection = app.findCollectionByNameOrId("pbc_1063824264")
unmarshal({
"indexes": [
"CREATE UNIQUE INDEX `idx_badge_progress_player_badge` ON `badge_progress` (`player`, `badge`)"
]
}, collection)
return app.save(collection)
}, (app) => {
const collection = app.findCollectionByNameOrId("pbc_1063824264")
unmarshal({
"indexes": []
}, collection)
return app.save(collection)
})