diff --git a/apps/tasks/src/jobs/refreshPatrons.ts b/apps/tasks/src/jobs/refreshPatrons.ts index 08df143d..624b2100 100644 --- a/apps/tasks/src/jobs/refreshPatrons.ts +++ b/apps/tasks/src/jobs/refreshPatrons.ts @@ -168,7 +168,7 @@ export default class RefreshPatrons extends TaskJob { // Reset rewards tier const user = await prisma.user.findFirst({ where: { patronId: dbPatron.id } }); - if (user && !patreonConfig.skipUsers.includes(user.id)) { + if (user && !patreonConfig.skipUsers.includes(user.id) && !user.tierManuallySet) { this.logger.info(`Resetting rewards for user ${user.id}`); operations.push(prisma.user.update({ where: { id: user.id }, data: { rewardTier: 0, driveEnabled: false } })); } @@ -227,7 +227,7 @@ export default class RefreshPatrons extends TaskJob { // Upsert in user table if (patron.discordId) { const user = await prisma.user.findFirst({ where: { patronId: patron.id } }); - if (user && user.id !== patron.discordId && !patreonConfig.skipUsers.includes(user.id)) { + if (user && user.id !== patron.discordId && !patreonConfig.skipUsers.includes(user.id) && !user.tierManuallySet) { this.logger.info(`Removing patronage for ${user.id} due to clashing with ${patron.discordId} (${patron.id})`); operations.push(prisma.user.update({ where: { id: user.id }, data: { patronId: undefined, rewardTier: 0, driveEnabled: false } })); } @@ -244,7 +244,7 @@ export default class RefreshPatrons extends TaskJob { } else if (!patreonConfig.skipUsers.includes(patron.id)) { // Find if this person is a patron, and give them a tier if so const user = await prisma.user.findFirst({ where: { patronId: patron.id } }); - if (!user || patreonConfig.skipUsers.includes(user.id)) continue; + if (!user || user.tierManuallySet || patreonConfig.skipUsers.includes(user.id)) continue; const tier = this.determineRewardTier(patron); if (user.rewardTier === tier) continue; this.logger.log(`Updating user ${user.id} reward tier for patron ${patron.id} (${patron.name}, tier=${tier})`); diff --git a/package.json b/package.json index ff04a568..18b089d0 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "sync:dev": "yarn manypkg run bot sync:dev", "run-job": "yarn manypkg run tasks run-job", "prisma:generate": "prisma generate && yarn manypkg run bot prisma:generate && yarn manypkg run dashboard prisma:generate && yarn manypkg run tasks prisma:generate", - "prisma:deploy": "prisma migrate deploy" + "prisma:deploy": "prisma migrate deploy", + "prisma:dev": "prisma migrate dev" }, "repository": { "type": "git", diff --git a/prisma/migrations/20241129014014_tier_manually_set/migration.sql b/prisma/migrations/20241129014014_tier_manually_set/migration.sql new file mode 100644 index 00000000..5dd24b30 --- /dev/null +++ b/prisma/migrations/20241129014014_tier_manually_set/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "tierManuallySet" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 99a52518..725b9136 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,8 +13,9 @@ datasource db { model User { id String @id - rewardTier Int @default(0) - patronId String? + rewardTier Int @default(0) + patronId String? + tierManuallySet Boolean @default(false) webapp Boolean @default(false)