Skip to content

chore(be): set profileImageUrl seed into username for recent users & add not null constraint#3597

Open
zero1177 wants to merge 2 commits into
feat/remove-whitelistfrom
chore/profileImage-schema
Open

chore(be): set profileImageUrl seed into username for recent users & add not null constraint#3597
zero1177 wants to merge 2 commits into
feat/remove-whitelistfrom
chore/profileImage-schema

Conversation

@zero1177
Copy link
Copy Markdown
Contributor

Description

  1. migration.sql 수정
  • 기존 user들의 profileImageUrl 필드의 seed 값을 username으로 채워넣는 SQL 작성
    https://api.dicebear.com/9.x/notionists/svg?seed={username}
  • 이후 profileImageUrl 필드를 not null로 제약조건을 추가하는 SQL 작성
  1. seed.ts
    profileImageUrl 시드값을 채워넣는 일부 값을 실제 dicebear Url에 맞춰 수정

Copilot AI review requested due to automatic review settings May 28, 2026 07:49
@zero1177 zero1177 self-assigned this May 28, 2026
@zero1177 zero1177 requested review from juheon429 and nhjbest22 May 28, 2026 07:49
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +9 to +12
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"
);
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;

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.profileImageUrl in Prisma schema from nullable to required.
  • Add a migration to populate profile_image_url and 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.

Comment on lines +8 to +12
-- 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 119 to 124
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants