diff --git a/src/lib/rawSql.ts b/src/lib/rawSql.ts index 54b68fc695..45def967e9 100644 --- a/src/lib/rawSql.ts +++ b/src/lib/rawSql.ts @@ -1,4 +1,5 @@ import { Prisma } from '@prisma/client'; +import { logError } from './util/logError'; const u = Prisma.UserScalarFieldEnum; @@ -14,3 +15,14 @@ SET ${u.cl_array} = ( ) WHERE ${u.id} = '${userID}';` }; + +export async function loggedRawPrismaQuery(query: string): Promise { + try { + const result = await prisma.$queryRawUnsafe(query); + return result; + } catch (err) { + logError(err, { query: query.slice(0, 100) }); + } + + return null; +} diff --git a/src/lib/rolesTask.ts b/src/lib/rolesTask.ts index 2145740d7d..eb76b1d692 100644 --- a/src/lib/rolesTask.ts +++ b/src/lib/rolesTask.ts @@ -1,4 +1,4 @@ -import { noOp, uniqueArr } from 'e'; +import { noOp, notEmpty, uniqueArr } from 'e'; import { SupportServer } from '../config'; import { BadgesEnum, Roles } from '../lib/constants'; @@ -11,6 +11,7 @@ import { partition } from 'remeda'; import z from 'zod'; import { type CommandResponse, Stopwatch, convertXPtoLVL, getUsernameSync, returnStringOrFile } from '../lib/util'; import { ClueTiers } from './clues/clueTiers'; +import { loggedRawPrismaQuery } from './rawSql'; import { TeamLoot } from './simulation/TeamLoot'; import { SkillsArray } from './skilling/types'; import type { ItemBank } from './types'; @@ -385,8 +386,8 @@ export async function runRolesTask(dryRun: boolean): Promise { debugLog(`Finished role functions, ${results.length} results`); - const allBadgeIDs = uniqueArr(results.map(i => i.badge)); - const allRoleIDs = uniqueArr(results.map(i => i.roleID)); + const allBadgeIDs = uniqueArr(results.map(i => i.badge)).filter(notEmpty); + const allRoleIDs = uniqueArr(results.map(i => i.roleID)).filter(notEmpty); if (!dryRun) { const roleNames = new Map(); @@ -396,7 +397,7 @@ export async function runRolesTask(dryRun: boolean): Promise { // Remove all top badges from all users (and add back later) debugLog('Removing badges...'); const badgeIDs = `ARRAY[${allBadgeIDs.join(',')}]`; - await prisma.$queryRawUnsafe(` + await loggedRawPrismaQuery(` UPDATE users SET badges = badges - ${badgeIDs} WHERE badges && ${badgeIDs}