mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-02 16:20:36 -05:00
Migration for western LB (#472)
* Migration * Bot freeAgents API get profile updatedAt * Add isJP script
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
"prebuild": "ts-node prisma/scripts/preBuild.ts",
|
||||
"mongo": "ts-node prisma/scripts/dataFromMongo.ts",
|
||||
"top500": "ts-node prisma/scripts/top500jsons.ts",
|
||||
"isJP": "ts-node prisma/scripts/isJP.ts",
|
||||
"league": "cross-env NODE_OPTIONS=--max-old-space-size=8192 ts-node prisma/scripts/leagueJsons.ts",
|
||||
"ex:clean": "cross-env NODE_ENV=development lingui extract --clean && npm run prettier:format",
|
||||
"compile": "lingui compile",
|
||||
|
||||
@@ -25,7 +25,9 @@ const teamsFreeAgentsHandler = async (
|
||||
discordAvatar: true,
|
||||
username: true,
|
||||
discriminator: true,
|
||||
profile: { select: { country: true, weaponPool: true } },
|
||||
profile: {
|
||||
select: { country: true, weaponPool: true, updatedAt: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,8 +4,11 @@ import { PrismaClient } from "@prisma/client";
|
||||
let prisma: PrismaClient;
|
||||
|
||||
if (!global.prisma) {
|
||||
//global.prisma = new PrismaClient({ log: ["query", "info", "warn"] });
|
||||
global.prisma = new PrismaClient();
|
||||
global.prisma = new PrismaClient(
|
||||
process.env.NODE_ENV !== "production"
|
||||
? { log: ["query", "info", "warn"] }
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
|
||||
prisma = global.prisma;
|
||||
|
||||
24
prisma/migrations/20210501111558_add_is_jp/migration.sql
Normal file
24
prisma/migrations/20210501111558_add_is_jp/migration.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `canPostEvents` on the `User` table. All the data in the column will be lost.
|
||||
- You are about to drop the `Feedback` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Feedback" DROP CONSTRAINT "Feedback_userId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Player" ADD COLUMN "isJP" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Profile" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" DROP COLUMN "canPostEvents";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "Feedback";
|
||||
|
||||
-- DropEnum
|
||||
DROP TYPE "FeedbackEmoji";
|
||||
@@ -17,7 +17,6 @@ model User {
|
||||
teamId Int?
|
||||
ladderTeamId Int?
|
||||
patreonTier Int?
|
||||
canPostEvents Boolean @default(false)
|
||||
profile Profile?
|
||||
player Player?
|
||||
builds Build[]
|
||||
@@ -36,7 +35,6 @@ model User {
|
||||
votesMade PlusBallot[]
|
||||
votesReceived PlusBallot[] @relation("Voter")
|
||||
votingSummaries PlusVotingSummary[]
|
||||
feedback Feedback[]
|
||||
calendarEvents CalendarEvent[]
|
||||
}
|
||||
|
||||
@@ -49,6 +47,7 @@ model Profile {
|
||||
sensStick Float?
|
||||
bio String?
|
||||
weaponPool String[]
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
customUrlPath String? @unique
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId Int @unique
|
||||
@@ -121,6 +120,7 @@ model Player {
|
||||
userId Int? @unique
|
||||
name String?
|
||||
principalId String?
|
||||
isJP Boolean @default(false)
|
||||
placements XRankPlacement[]
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
leaguePlacements LeagueSquadMember[]
|
||||
@@ -406,22 +406,6 @@ model PlusVotingSummary {
|
||||
@@unique([userId, tier, month, year])
|
||||
}
|
||||
|
||||
enum FeedbackEmoji {
|
||||
STARSTRUCK
|
||||
SMILE
|
||||
CONFUSED
|
||||
SOB
|
||||
}
|
||||
|
||||
model Feedback {
|
||||
id Int @id @default(autoincrement())
|
||||
text String
|
||||
emoji FeedbackEmoji?
|
||||
mobile Boolean @default(false)
|
||||
userId Int?
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
}
|
||||
|
||||
enum TournamentFormat {
|
||||
SE
|
||||
DE
|
||||
|
||||
48
prisma/scripts/isJP.ts
Normal file
48
prisma/scripts/isJP.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import prisma from "../client";
|
||||
|
||||
const main = async () => {
|
||||
// const players = await prisma.player.findMany({
|
||||
// where: { NOT: { name: null } },
|
||||
// });
|
||||
|
||||
// const jpCharaRegex = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/;
|
||||
|
||||
// const playersWithWesternNames: string[] = [];
|
||||
|
||||
// for (const player of players) {
|
||||
// if (jpCharaRegex.test(player.name!)) {
|
||||
// playersWithWesternNames.push(player.switchAccountId);
|
||||
// }
|
||||
// }
|
||||
|
||||
const players = await prisma.player.findMany({
|
||||
where: { NOT: { name: null }, isJP: false },
|
||||
include: { leaguePlacements: { include: { squad: true } } },
|
||||
});
|
||||
|
||||
const actuallyJP: string[] = [];
|
||||
|
||||
for (const player of players) {
|
||||
let ratio = 0;
|
||||
for (const placement of player.leaguePlacements) {
|
||||
if (placement.squad.region === "JP") ratio--;
|
||||
else ratio++;
|
||||
}
|
||||
if (ratio < 0) {
|
||||
actuallyJP.push(player.switchAccountId);
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.player.updateMany({
|
||||
data: { isJP: true },
|
||||
where: { switchAccountId: { in: actuallyJP } },
|
||||
});
|
||||
|
||||
console.log("done", players.length);
|
||||
};
|
||||
|
||||
main()
|
||||
.catch((e) => console.error(e))
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user