fixed so the code compiles
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `username` on table `User` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- Backfill: assign a unique username derived from email or googleId for rows with NULL username
|
||||
UPDATE "User"
|
||||
SET "username" = lower(regexp_replace(split_part("email", '@', 1), '[^a-zA-Z0-9_]', '', 'g'))
|
||||
WHERE "username" IS NULL;
|
||||
|
||||
-- Ensure uniqueness by appending a suffix for any collisions
|
||||
UPDATE "User" u
|
||||
SET "username" = u."username" || '_' || substr(u."id", 1, 6)
|
||||
WHERE (
|
||||
SELECT COUNT(*) FROM "User" u2
|
||||
WHERE u2."username" = u."username" AND u2."id" != u."id"
|
||||
) > 0;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ALTER COLUMN "username" SET NOT NULL;
|
||||
+16
-2
@@ -36,13 +36,14 @@ model User {
|
||||
googleId String @unique
|
||||
email String @unique
|
||||
displayName String
|
||||
username String? @unique
|
||||
username String @unique
|
||||
avatarUrl String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
sessions GameSession[]
|
||||
sessions GameSession[]
|
||||
leaderboardEntries LeaderboardEntry[]
|
||||
matchResults MatchResult[]
|
||||
}
|
||||
|
||||
model Question {
|
||||
@@ -103,3 +104,16 @@ model LeaderboardEntry {
|
||||
|
||||
@@unique([userId, grade])
|
||||
}
|
||||
|
||||
model MatchResult {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
grade Grade
|
||||
won Boolean
|
||||
eloChange Int
|
||||
eloAfter Int
|
||||
timeSpentMs Int?
|
||||
playedAt DateTime @default(now())
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user