chore(be): set profileImageUrl seed into username for recent users & add not null constraint#3597
chore(be): set profileImageUrl seed into username for recent users & add not null constraint#3597zero1177 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request makes the profileImageUrl field non-nullable in the Prisma schema, updates the database seed data, and adds a migration script to set a default URL and apply the NOT NULL constraint. A critical issue was identified in the migration script where the UPDATE statement lacks a WHERE clause, which would overwrite existing valid profile image URLs instead of only updating NULL values.
| 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" | ||
| ); |
There was a problem hiding this comment.
현재 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;There was a problem hiding this comment.
Pull request overview
This PR backfills user_profile.profile_image_url using a Dicebear URL seeded by username, then enforces a NOT NULL constraint so every UserProfile has a profile image URL going forward.
Changes:
- Update
UserProfile.profileImageUrlin Prisma schema from nullable to required. - Add a migration to populate
profile_image_urland then apply a NOT NULL constraint. - Adjust seed data to use real Dicebear URLs instead of placeholder strings.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/backend/prisma/seed.ts | Updates seeded UserProfile.profileImageUrl values to Dicebear URLs. |
| apps/backend/prisma/schema.prisma | Makes UserProfile.profileImageUrl required (non-nullable). |
| apps/backend/prisma/migrations/20260528070352_add_not_null_constraint_to_profile_image_url_field/migration.sql | Backfills profile_image_url and applies a NOT NULL constraint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -- 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" | ||
| ); |
| id Int @id @default(autoincrement()) | ||
| 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") |
Description
https://api.dicebear.com/9.x/notionists/svg?seed={username}profileImageUrl 시드값을 채워넣는 일부 값을 실제 dicebear Url에 맞춰 수정