mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Script to fix Skill objects of old format
This commit is contained in:
parent
5a2fcf7a9f
commit
74efcdc5e0
35
scripts/delete-skills-without-results.ts
Normal file
35
scripts/delete-skills-without-results.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import "dotenv/config";
|
||||
import { db } from "~/db/sql";
|
||||
import { logger } from "~/utils/logger";
|
||||
|
||||
async function main() {
|
||||
const skills = await db
|
||||
.selectFrom("Skill")
|
||||
.leftJoin("TournamentResult", (join) =>
|
||||
join
|
||||
.onRef("TournamentResult.tournamentId", "=", "Skill.tournamentId")
|
||||
.onRef("TournamentResult.userId", "=", "Skill.userId"),
|
||||
)
|
||||
.select(["Skill.id"])
|
||||
.where("Skill.tournamentId", "is not", null)
|
||||
.where("TournamentResult.tournamentId", "is", null)
|
||||
.execute();
|
||||
|
||||
logger.info(`Found ${skills.length} skills without results`);
|
||||
|
||||
await db
|
||||
.updateTable("Skill")
|
||||
.set({
|
||||
tournamentId: null,
|
||||
})
|
||||
.where(
|
||||
"id",
|
||||
"in",
|
||||
skills.map((skill) => skill.id),
|
||||
)
|
||||
.execute();
|
||||
|
||||
logger.info("Deleted skills without results");
|
||||
}
|
||||
|
||||
void main();
|
||||
Loading…
Reference in New Issue
Block a user