sendou.ink/migrations/145-user-weapon-pool-table.js
Kalle d278a15504
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
10 star weapon pool (#3108)
2026-06-01 18:20:47 +03:00

57 lines
1.4 KiB
JavaScript

export function up(db) {
db.transaction(() => {
db.prepare(
/* sql */ `
create table "UserWeaponPool" (
"userId" integer not null,
"sortOrder" integer not null,
"weaponSplId" integer not null,
"isFavorite" integer not null default 0,
foreign key ("userId") references "User"("id") on delete cascade,
primary key ("userId", "sortOrder")
) strict
`,
).run();
db.prepare(
/* sql */ `
insert into "UserWeaponPool" ("userId", "sortOrder", "weaponSplId", "isFavorite")
select
u."id",
je."key",
json_extract(je."value", '$.weaponSplId'),
coalesce(json_extract(je."value", '$.isFavorite'), 0)
from "User" u, json_each(u."weaponPool") je
where u."weaponPool" is not null
`,
).run();
db.prepare(
/* sql */ `
create table "TenStarWeapon" (
"userId" integer not null,
"weaponSplId" integer not null,
foreign key ("userId") references "User"("id") on delete cascade,
primary key ("userId", "weaponSplId")
) strict
`,
).run();
db.prepare(
/* sql */ `
insert into "TenStarWeapon" ("userId", "weaponSplId")
select distinct sp."userId", xrp."weaponSplId"
from "XRankPlacement" xrp
inner join "SplatoonPlayer" sp on sp."id" = xrp."playerId"
where sp."userId" is not null
and (
xrp."region" = 'JPN'
or (xrp."region" = 'WEST' and xrp."rank" <= 100)
)
`,
).run();
db.pragma("foreign_key_check");
})();
}