uuid7으로 필드 및 처리관련 수정

This commit is contained in:
Dohyun Lim committed 2026-01-28 16:35:08 +09:00
1 parent aa8d9d7c14
commit 32ae5530b6
26 files changed
+2346 -901

No files matched your search

+25 -27
View File
@@ -14,7 +14,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database.session import Base
if TYPE_CHECKING:
from app.home.models import UserProject
from app.home.models import Project
class User(Base):
@@ -26,7 +26,7 @@ class User(Base):
Attributes:
id: 고유 식별자 (자동 증가)
kakao_id: 카카오 고유 ID (필수, 유니크)
user_ksuid: 사용자 식별을 위한 KSUID (필수, 유니크)
user_uuid: 사용자 식별을 위한 UUID7 (필수, 유니크)
email: 이메일 주소 (선택, 카카오에서 제공 시)
nickname: 카카오 닉네임 (선택)
profile_image_url: 카카오 프로필 이미지 URL (선택)
@@ -54,8 +54,7 @@ class User(Base):
- 실제 데이터는 DB에 유지됨
Relationships:
user_projects: Project와의 M:N 관계 (중계 테이블 통한 연결)
projects: 사용자가 참여한 프로젝트 목록 (Association Proxy)
projects: 사용자가 소유한 프로젝트 목록 (1:N 관계)
카카오 API 응답 필드 매핑:
- kakao_id: id (카카오 회원번호)
@@ -70,7 +69,7 @@ class User(Base):
__tablename__ = "user"
__table_args__ = (
Index("idx_user_kakao_id", "kakao_id"),
Index("idx_user_ksuid", "user_ksuid"),
Index("idx_user_uuid", "user_uuid"),
Index("idx_user_email", "email"),
Index("idx_user_phone", "phone"),
Index("idx_user_is_active", "is_active"),
@@ -105,11 +104,11 @@ class User(Base):
comment="카카오 고유 ID (회원번호)",
)
user_ksuid: Mapped[str] = mapped_column(
String(27),
user_uuid: Mapped[str] = mapped_column(
String(36),
nullable=False,
unique=True,
comment="사용자 식별을 위한 KSUID (K-Sortable Unique Identifier)",
comment="사용자 식별을 위한 UUID7 (시간순 정렬 가능한 UUID)",
)
# ==========================================================================
@@ -231,16 +230,15 @@ class User(Base):
)
# ==========================================================================
# Project M:N 관계 (중계 테이블 UserProject 통한 연결)
# Project 1:N 관계 (한 사용자가 여러 프로젝트를 소유)
# ==========================================================================
# back_populates: UserProject.user와 양방향 연결
# cascade: User 삭제 시 UserProject 레코드도 삭제 (Project는 유지)
# back_populates: Project.owner와 양방향 연결
# cascade: 사용자 삭제 시 프로젝트는 유지 (owner가 NULL로 설정됨)
# lazy="selectin": N+1 문제 방지
# ==========================================================================
user_projects: Mapped[List["UserProject"]] = relationship(
"UserProject",
back_populates="user",
cascade="all, delete-orphan",
projects: Mapped[List["Project"]] = relationship(
"Project",
back_populates="owner",
lazy="selectin",
)
@@ -291,7 +289,7 @@ class RefreshToken(Base):
Attributes:
id: 고유 식별자 (자동 증가)
user_id: 사용자 외래키 (User.id 참조)
user_ksuid: 사용자 KSUID (User.user_ksuid 참조)
user_uuid: 사용자 UUID (User.user_uuid 참조)
token_hash: 리프레시 토큰의 SHA-256 해시값 (원본 저장 X)
expires_at: 토큰 만료 일시
is_revoked: 토큰 폐기 여부 (로그아웃 시 True)
@@ -309,7 +307,7 @@ class RefreshToken(Base):
__tablename__ = "refresh_token"
__table_args__ = (
Index("idx_refresh_token_user_id", "user_id"),
Index("idx_refresh_token_user_ksuid", "user_ksuid"),
Index("idx_refresh_token_user_uuid", "user_uuid"),
Index("idx_refresh_token_token_hash", "token_hash", unique=True),
Index("idx_refresh_token_expires_at", "expires_at"),
Index("idx_refresh_token_is_revoked", "is_revoked"),
@@ -335,10 +333,10 @@ class RefreshToken(Base):
comment="사용자 외래키 (User.id 참조)",
)
user_ksuid: Mapped[str] = mapped_column(
String(27),
user_uuid: Mapped[str] = mapped_column(
String(36),
nullable=False,
comment="사용자 KSUID (User.user_ksuid 참조)",
comment="사용자 UUID (User.user_uuid 참조)",
)
token_hash: Mapped[str] = mapped_column(
@@ -438,12 +436,12 @@ class SocialAccount(Base):
__tablename__ = "social_account"
__table_args__ = (
Index("idx_social_account_user_id", "user_id"),
Index("idx_social_account_user_uuid", "user_uuid"),
Index("idx_social_account_platform", "platform"),
Index("idx_social_account_is_active", "is_active"),
Index(
"uq_user_platform_account",
"user_id",
"user_uuid",
"platform",
"platform_user_id",
unique=True,
@@ -466,11 +464,11 @@ class SocialAccount(Base):
comment="고유 식별자",
)
user_id: Mapped[int] = mapped_column(
BigInteger,
ForeignKey("user.id", ondelete="CASCADE"),
user_uuid: Mapped[str] = mapped_column(
String(36),
ForeignKey("user.user_uuid", ondelete="CASCADE"),
nullable=False,
comment="사용자 외래키 (User.id 참조)",
comment="사용자 외래키 (User.user_uuid 참조)",
)
# ==========================================================================
@@ -573,7 +571,7 @@ class SocialAccount(Base):
return (
f"<SocialAccount("
f"id={self.id}, "
f"user_id={self.user_id}, "
f"user_uuid='{self.user_uuid}', "
f"platform='{self.platform}', "
f"platform_username='{self.platform_username}', "
f"is_active={self.is_active}"