Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Warnings:

- Made the column `profile_image_url` on table `user_profile` required. This step will fail if there are existing NULL values in that column.

*/

-- Set default profileImageUrl seed to username for users
UPDATE "public"."user_profile"
SET "profile_image_url" = 'https://api.dicebear.com/9.x/notionists/svg?seed=' || (
SELECT "username" FROM "public"."user" WHERE "user"."id" = "user_profile"."user_id"
);
Comment on lines +9 to +12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

현재 UPDATE 문은 WHERE 조건절이 없기 때문에, 이미 유효한 profile_image_url을 설정한 기존 사용자들의 데이터까지 모두 기본 Dicebear URL로 덮어쓰게(overwrite) 됩니다. 이는 운영 환경에서 심각한 데이터 유실을 초래할 수 있습니다.\n\nNOT NULL 제약 조건을 안전하게 추가하기 위해, 기존에 NULL인 데이터만 기본값으로 채워 넣도록 WHERE "profile_image_url" IS NULL 조건을 추가하는 것이 안전합니다. 만약 기존의 특정 패턴(예: dicebear:...)만 변경하려는 의도라면, 해당 패턴만 지정하여 업데이트하도록 조건을 세분화해야 합니다.

UPDATE "public"."user_profile"\nSET "profile_image_url" = 'https://api.dicebear.com/9.x/notionists/svg?seed=' || (\n  SELECT "username" FROM "public"."user" WHERE "user"."id" = "user_profile"."user_id"\n)\nWHERE "profile_image_url" IS NULL;

Comment on lines +8 to +12

-- Make profileImageUrl not null
ALTER TABLE "public"."user_profile" ALTER COLUMN "profile_image_url" SET NOT NULL;



2 changes: 1 addition & 1 deletion apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ model UserProfile {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @unique @map("user_id")
realName String @map("real_name")
profileImageUrl String? @map("profile_image_url")
profileImageUrl String @map("profile_image_url")
createTime DateTime @default(now()) @map("create_time")
updateTime DateTime @updatedAt @map("update_time")

Expand Down
6 changes: 3 additions & 3 deletions apps/backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ const createUsers = async () => {
data: {
userId: superAdminUser.id,
realName: 'Yuljeon Kim',
profileImageUrl: 'dicebear:super.com'
profileImageUrl: 'https://api.dicebear.com/9.x/notionists/svg?seed=super'
}
})

await prisma.userProfile.create({
data: {
userId: adminUser.id,
realName: 'Admin Kim',
profileImageUrl: 'dicebear:user02.com'
profileImageUrl: 'https://api.dicebear.com/9.x/notionists/svg?seed=admin'
}
})

Expand All @@ -199,7 +199,7 @@ const createUsers = async () => {
data: {
userId: users[0].id,
realName: 'Myeongryun Lee',
profileImageUrl: 'dicebear:user01'
profileImageUrl: 'https://api.dicebear.com/9.x/notionists/svg?seed=user01'
}
})
}
Expand Down
Loading