refactor(ssulbox): 자동 마이그레이션 제거, DDL 을 수동 문서로 이관

This commit is contained in:
skkim committed 2026-08-11 11:03:03 +09:00
1 parent 666c3bf6d1
commit ed1ba71bfe
7 files changed
+193 -641

No files matched your search

+11 -203
View File
@@ -12,8 +12,9 @@ mysql_engine/charset/collate 명시, 컬럼마다 comment.
`updated_at` 은 대응 castad 테이블이 가진 경우에만 둔다 — `video`/`comment`/`project`/
`lyric`/`song` 은 상태 전이를 겪으면서도 `created_at` 만 갖고, `social_upload` 만 예외다.
주의: Alembic 이 없다. 이 파일을 고친 뒤에는 app/ssulbox/migration.py 의
ensure_ssulbox_schema() 에 대응 DDL 을 함께 추가해야 운영 DB 에 반영된다.
주의: Alembic 이 없고 **DB 변경은 전부 수동**이 방침이다. 이 파일을 고쳐도 앱은
어떤 DDL 도 실행하지 않는다 — 대응 SQL 을 docs/manual_ddl/ 에 추가하고 배포 전에
직접 실행해야 운영 DB 에 반영된다. (자동 마이그레이션은 2026-07-30 제거)
"""
from datetime import datetime
@@ -26,17 +27,16 @@ from sqlalchemy import (
ForeignKey,
Index,
Integer,
JSON,
String,
Text,
func,
)
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm import Mapped, mapped_column
from app.database.session import Base
if TYPE_CHECKING:
from app.user.models import SocialAccount
pass
# MySQL 전용 테이블 옵션 (castad 공통)
_MYSQL_OPTS = {
@@ -207,7 +207,7 @@ class SsulContent(Base):
# title / caption / views / like_count / comment_count 는 두지 않는다.
# - castad `video` 도 제목을 갖지 않고 목록 표시는 store_name 으로 한다.
# SNS 업로드 제목·설명은 업로드 시점에 작성해 ssul_social_upload 에 담고,
# SNS 업로드 제목·설명은 업로드 시점에 작성해 social_upload 에 담고,
# 다운로드 파일명은 프론트가 정한다.
# - 좋아요/댓글 수는 castad `video_reaction` / `comment` 상관 서브쿼리로 집계한다
# (2026-07-30 병합. 썰박스 행은 content_id 가 채워진다).
@@ -246,200 +246,8 @@ class SsulContent(Base):
# 종류별 키를 지원해 Redis write-behind 를 그대로 공유할 수 있었다.
class SsulSocialUpload(Base):
"""썰박스 콘텐츠의 SNS 업로드 기록.
castad `social_upload` 를 재사용하지 못하는 이유: 그쪽 `video_id` 가 NOT NULL 이고
`Video` 를 lazy="selectin" 으로 물고 있어, nullable 로 바꾸면
app/social/services/upload_service.py · app/dashboard/migration.py · 백오피스가
모두 영향을 받는다. 대신 구조를 그대로 본떠 신설한다 —
**컬럼 구성은 castad social_upload 와 완전히 동일하다(21개).**
차이는 두 가지뿐이다: content_id 가 bigint(ssul_content.id 를 따름), 그리고
DB 기본값(server_default)을 명시해 ORM 을 우회한 INSERT 도 안전하게 했다.
예약 업로드(`scheduled_at`)는 castad 에서 이미 동작한다
(app/social/services/upload_service.py 가 예약/즉시를 분기하고 충돌 검사도 한다).
이식 시 같은 서비스 로직을 재사용할 수 있다.
알려진 대가: app/dashboard/migration.py 가 SocialUpload 만 읽으므로 썰박스 업로드는
대시보드 통계에 잡히지 않는다. 통합 시점은 별도 결정 사항이다.
"""
__tablename__ = "ssul_social_upload"
__table_args__ = (
# (content_id, social_account_id, upload_seq) 가 앞 2개 컬럼 조회도 커버하므로
# (content_id, social_account_id) 를 따로 두지 않는다.
# 참고: castad social_upload 에는 이 중복이 남아 있다(video_account, video_id).
Index("idx_ssul_upload_seq", "content_id", "social_account_id", "upload_seq"),
Index("idx_ssul_upload_user", "user_uuid"),
Index("idx_ssul_upload_status", "status"),
Index("idx_ssul_upload_platform", "platform"),
Index("idx_ssul_upload_created_at", "created_at"),
_MYSQL_OPTS,
)
id: Mapped[int] = mapped_column(
BigInteger,
primary_key=True,
nullable=False,
autoincrement=True,
comment="고유 식별자",
)
user_uuid: Mapped[str] = mapped_column(
String(36),
ForeignKey("user.user_uuid", ondelete="CASCADE"),
nullable=False,
comment="업로드한 사용자 UUID",
)
content_id: Mapped[int] = mapped_column(
BigInteger,
ForeignKey("ssul_content.id", ondelete="CASCADE"),
nullable=False,
comment="업로드 대상 콘텐츠 ID",
)
social_account_id: Mapped[int] = mapped_column(
# social_account.id 는 BIGINT 가 아니라 INT 다(castad social_upload 도 동일).
# BigInteger 로 두면 MySQL 이 FK 타입 불일치(errno 3780)로 생성을 거부한다.
Integer,
ForeignKey("social_account.id", ondelete="CASCADE"),
nullable=False,
comment="연동 SNS 계정 ID (castad social_account 재사용)",
)
upload_seq: Mapped[int] = mapped_column(
Integer,
nullable=False,
default=1,
server_default="1",
comment="(content, account) 조합 내 업로드 순번 — 재업로드 버전 관리",
)
platform: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="플랫폼 (youtube/instagram/facebook/tiktok)",
)
status: Mapped[str] = mapped_column(
String(20),
nullable=False,
default="pending",
server_default="pending",
comment="상태 (scheduled/pending/uploading/processing/completed/failed)",
)
upload_progress: Mapped[int] = mapped_column(
Integer,
nullable=False,
default=0,
server_default="0",
comment="업로드 진행률 (0~100)",
)
platform_video_id: Mapped[Optional[str]] = mapped_column(
String(100),
nullable=True,
comment="플랫폼 측 영상 ID",
)
platform_url: Mapped[Optional[str]] = mapped_column(
String(500),
nullable=True,
comment="플랫폼 측 영상 URL",
)
title: Mapped[str] = mapped_column(
String(200),
nullable=False,
default="",
server_default="",
comment="업로드 제목",
)
description: Mapped[Optional[str]] = mapped_column(
Text,
nullable=True,
comment="업로드 설명",
)
tags: Mapped[Optional[list]] = mapped_column(
JSON,
nullable=True,
comment="태그 목록",
)
privacy_status: Mapped[str] = mapped_column(
String(20),
nullable=False,
default="public",
server_default="public",
comment="공개 범위 (public/unlisted/private)",
)
scheduled_at: Mapped[Optional[datetime]] = mapped_column(
DateTime,
nullable=True,
comment="예약 업로드 시각 (NULL 이면 즉시 업로드)",
)
platform_options: Mapped[Optional[dict]] = mapped_column(
JSON,
nullable=True,
comment="플랫폼별 추가 옵션",
)
error_message: Mapped[Optional[str]] = mapped_column(
Text,
nullable=True,
comment="실패 사유",
)
retry_count: Mapped[int] = mapped_column(
Integer,
nullable=False,
default=0,
server_default="0",
comment="재시도 횟수",
)
uploaded_at: Mapped[Optional[datetime]] = mapped_column(
DateTime,
nullable=True,
comment="업로드 완료 일시",
)
created_at: Mapped[datetime] = mapped_column(
DateTime,
nullable=False,
server_default=func.now(),
comment="생성 일시",
)
updated_at: Mapped[datetime] = mapped_column(
DateTime,
nullable=False,
server_default=func.now(),
onupdate=func.now(),
comment="수정 일시",
)
content: Mapped["SsulContent"] = relationship(
"SsulContent",
foreign_keys=[content_id],
lazy="noload",
)
social_account: Mapped["SocialAccount"] = relationship(
"SocialAccount",
foreign_keys=[social_account_id],
lazy="noload",
)
def __repr__(self) -> str:
return (
f"<SsulSocialUpload(id={self.id}, content_id={self.content_id}, "
f"platform='{self.platform}', status='{self.status}')>"
)
# SNS 업로드 모델도 여기 없다.
# castad `social_upload` 에 병합됐다(2026-07-30, docs/manual_ddl/
# 2026-07-30-social-upload-merge.sql) — 그쪽 행은 ADO2 면 video_id, 썰박스면
# content_id 가 채워지고 CHECK 로 하나만 강제한다. 덕분에 dashboard 통계가
# 썰박스 업로드를 무수정으로 집계한다(SocialUpload 만 읽고 video_id 는 안 본다).