sendou.ink/scripts/transfer-weapon-pools.ts
Kalle 7dec8c572e
SendouQ Season 2 changes (#1542)
* Initial

* Saves preferences

* Include TW

* mapModePreferencesToModeList

* mapPoolFromPreferences initial

* Preference to map pool

* Adjust seed

* q.looking tests

* adds about created map preferences to memento in the correct spot (two preferrers)

* Failing test about modes

* Mode preferences to memento

* Remove old Plus Voting code

* Fix seeding

* find match by id via kysely

* View map memento

* Fix up map list generation logic

* Mode memento info

* Future match modes

* Add TODO

* Migration number

* Migrate test DB

* Remove old map pool code

* createGroupFromPrevious new

* Settings styling

* VC to settings

* Weapon pool

* Add TODOs

* Progress

* Adjust mode exclusion policy

* Progress

* Progress

* Progress

* Notes in progress

* Note feedback after submit

* Textarea styling

* Unskip tests

* Note sorting failing test

* Private note in Q

* Ownerpicksmaps later

* New bottom section

* Mobile layout initial

* Add basic match meta

* Tabs initial

* Sticky tab

* Unseen messages in match page

* Front page i18n

* Settings i18n

* Looking 18n

* Chat i18n

* Progress

* Tranfer weapon pools script

* Sticky on match page

* Match page translations

* i18n - tiers page

* Preparing page i18n

* Icon

* Show add note right after report
2023-11-30 20:57:06 +02:00

49 lines
1.1 KiB
TypeScript

/* eslint-disable no-console */
import "dotenv/config";
import { db } from "~/db/sql";
async function main() {
const weaponPools = await db
.selectFrom("UserWeapon")
.select([
"UserWeapon.userId",
"UserWeapon.weaponSplId",
"UserWeapon.userId",
])
.where("UserWeapon.order", "!=", 5)
.orderBy("UserWeapon.order asc")
.execute();
// group by userId
const weaponPoolsByUserId = weaponPools.reduce(
(acc, weaponPool) => {
if (!acc[weaponPool.userId]) {
acc[weaponPool.userId] = [];
}
acc[weaponPool.userId].push(weaponPool);
return acc;
},
{} as Record<string, typeof weaponPools>,
);
for (const [userId, weaponPools] of Object.entries(weaponPoolsByUserId)) {
const weaponPoolIds = weaponPools.map(
(weaponPool) => weaponPool.weaponSplId,
);
await db
.updateTable("User")
.set({
qWeaponPool: JSON.stringify(weaponPoolIds),
})
.where("User.id", "=", Number(userId))
.execute();
}
console.log("done with the transfer");
}
void main();