Files
o2o-weather/backend/common/database/model/models.py
T
minaChoi a9ddbaab3c feat: 피드를 시간대별 카드로 다시 짜고 하늘 배경·내 캐릭터 추가, 다른 시안 정리
- 피드: 그날 카드 12장을 03:00에 한 번에 만들고, 시간대(아침·낮·저녁·밤, 저녁은 일몰 2시간 전부터)마다 순서를 바꾸고 조건이 맞는 카드만 켠다. 새 카드 우산·특보, 내일 미리보기, 한 문장·시(예시 seed). 흐린 날 노을은 한 줄 카드.
- 캐시를 feed:{구}:{시간대}로 나누고 시간대 경계·일몰·예보 갱신 때 만료해 새 카드가 늦게 보이던 문제를 고친다.
- 히어로는 오늘 1위 각만 보여 준다.
- 각 점수·노을 점수를 7일 지나면 지운다.
- 화면 전체 하늘 배경(시간대별 색, 느린 일렁임, 밤 별)과 화면 끝까지 이어지는 위·아래 바.
- 상단바 로그인 버튼, 내 정보 창(캐릭터 6종·배경색 6종·오늘 기분 8종·닉네임·로그아웃), PATCH /v1/auth/me, 댓글·상단바에 캐릭터·배경색·기분 표시. users.character·color·mood 칸 추가.
- 카드 슬라이드와 가로 줄을 Embla 카로셀로 바꿔 PC에서도 마우스로 끌어 넘기고 화살표로 넘긴다.
- 좋아요·저장을 받아 둔 피드 데이터에도 반영해 다른 탭에 다녀와도 유지되게 고치고, 좋아요 때 하트가 터지는 애니메이션을 넣는다.
- 보내기에서 게시물을 인스타 스토리 크기(1080×1920) 이미지로 공유하거나 내려받는다 (modern-screenshot).
- 창이 열려 있는 동안 뒤 페이지 스크롤을 잠근다.
- 시안 B 확정: 시안 A 아이콘(public/a)과 쓰지 않는 전역 스타일·글꼴 삭제.
- 문서: 데이터 흐름 지도(backend/docs/data-flow-map.html), 확정 시안(docs/시안B_확정.html), 피드 기획 v2, 호출량·DB 크기 추정, data-pipeline 갱신. 보고 폴더와 예전 시안 html 삭제.
2026-10-02 15:47:20 +09:00

321 lines
14 KiB
Python

import uuid
from datetime import date, datetime
from decimal import Decimal
from typing import Optional
from sqlalchemy import BigInteger, Boolean, Date, DateTime, Integer, Numeric, SmallInteger, String, func
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class Region(Base):
__tablename__ = "region"
code: Mapped[str] = mapped_column(String(10), primary_key=True)
name: Mapped[str] = mapped_column(String(30))
short_name: Mapped[str] = mapped_column(String(20))
lat: Mapped[Decimal] = mapped_column(Numeric(8, 5))
lon: Mapped[Decimal] = mapped_column(Numeric(8, 5))
nx: Mapped[int] = mapped_column(SmallInteger)
ny: Mapped[int] = mapped_column(SmallInteger)
warning_zone_code: Mapped[str] = mapped_column(String(10))
mid_land_code: Mapped[str] = mapped_column(String(10))
mid_temp_code: Mapped[str] = mapped_column(String(10))
is_ranking_spot: Mapped[bool] = mapped_column(Boolean, default=False)
ranking_note: Mapped[Optional[str]] = mapped_column(String(30), nullable=True)
class WeatherHourly(Base):
__tablename__ = "weather_hourly"
region_code: Mapped[str] = mapped_column(String(10), primary_key=True)
forecast_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), primary_key=True)
temp_c: Mapped[Decimal] = mapped_column(Numeric(4, 1))
feels_c: Mapped[Decimal] = mapped_column(Numeric(4, 1))
discomfort_index: Mapped[int] = mapped_column(SmallInteger)
sky: Mapped[int] = mapped_column(SmallInteger)
rain_type: Mapped[int] = mapped_column(SmallInteger)
rain_prob: Mapped[int] = mapped_column(SmallInteger)
rain_mm: Mapped[Decimal] = mapped_column(Numeric(5, 1))
humidity: Mapped[int] = mapped_column(SmallInteger)
wind_ms: Mapped[Optional[Decimal]] = mapped_column(Numeric(4, 1), nullable=True)
issued_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
class WeatherDaily(Base):
__tablename__ = "weather_daily"
region_code: Mapped[str] = mapped_column(String(10), primary_key=True)
forecast_date: Mapped[date] = mapped_column(Date, primary_key=True)
temp_min_c: Mapped[Optional[Decimal]] = mapped_column(Numeric(4, 1), nullable=True)
temp_max_c: Mapped[Optional[Decimal]] = mapped_column(Numeric(4, 1), nullable=True)
sky: Mapped[int] = mapped_column(SmallInteger)
rain_type: Mapped[int] = mapped_column(SmallInteger)
rain_prob: Mapped[int] = mapped_column(SmallInteger)
issued_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
class SunTime(Base):
__tablename__ = "sun_time"
region_code: Mapped[str] = mapped_column(String(10), primary_key=True)
sun_date: Mapped[date] = mapped_column(Date, primary_key=True)
sunrise_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
sunset_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
dusk_end_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
sunset_azimuth: Mapped[int] = mapped_column(SmallInteger)
class AirStation(Base):
__tablename__ = "air_station"
station_name: Mapped[str] = mapped_column(String(30), primary_key=True)
lat: Mapped[Decimal] = mapped_column(Numeric(8, 5))
lon: Mapped[Decimal] = mapped_column(Numeric(8, 5))
class AirQuality(Base):
__tablename__ = "air_quality"
station_name: Mapped[str] = mapped_column(String(30), primary_key=True)
pm25: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
pm10: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
grade: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
measured_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
class WeatherWarning(Base):
__tablename__ = "weather_warning"
warning_zone_code: Mapped[str] = mapped_column(String(10), primary_key=True)
warning_type: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
level: Mapped[int] = mapped_column(SmallInteger)
class CloudHourly(Base):
__tablename__ = "cloud_hourly"
lat: Mapped[Decimal] = mapped_column(Numeric(5, 2), primary_key=True)
lon: Mapped[Decimal] = mapped_column(Numeric(5, 2), primary_key=True)
forecast_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), primary_key=True)
model: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
cloud_low: Mapped[int] = mapped_column(SmallInteger)
cloud_mid: Mapped[int] = mapped_column(SmallInteger)
cloud_high: Mapped[int] = mapped_column(SmallInteger)
class SkyScore(Base):
__tablename__ = "sky_score"
region_code: Mapped[str] = mapped_column(String(10), primary_key=True)
score_date: Mapped[date] = mapped_column(Date, primary_key=True)
sky_type: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
score: Mapped[int] = mapped_column(SmallInteger)
grade: Mapped[int] = mapped_column(SmallInteger)
confidence: Mapped[int] = mapped_column(SmallInteger)
best_times: Mapped[list] = mapped_column(JSONB)
computed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
class SunsetSpot(Base):
__tablename__ = "sunset_spot"
spot_id: Mapped[int] = mapped_column(Integer, primary_key=True)
region_code: Mapped[str] = mapped_column(String(10))
name: Mapped[str] = mapped_column(String(40))
description: Mapped[str] = mapped_column(String(100))
lat: Mapped[Decimal] = mapped_column(Numeric(8, 5))
lon: Mapped[Decimal] = mapped_column(Numeric(8, 5))
sort_order: Mapped[int] = mapped_column(SmallInteger, default=0)
class IndexDefinition(Base):
__tablename__ = "index_definition"
index_id: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
code: Mapped[str] = mapped_column(String(30), unique=True)
name: Mapped[str] = mapped_column(String(20))
icon: Mapped[str] = mapped_column(String(30))
category: Mapped[int] = mapped_column(SmallInteger)
is_fun: Mapped[bool] = mapped_column(Boolean)
is_core: Mapped[bool] = mapped_column(Boolean)
has_detail: Mapped[bool] = mapped_column(Boolean)
description: Mapped[str] = mapped_column(String(100))
windows: Mapped[list] = mapped_column(JSONB)
weight_temp: Mapped[int] = mapped_column(SmallInteger)
weight_rain: Mapped[int] = mapped_column(SmallInteger)
weight_wind: Mapped[int] = mapped_column(SmallInteger)
weight_humidity: Mapped[int] = mapped_column(SmallInteger)
weight_air: Mapped[int] = mapped_column(SmallInteger)
weight_time: Mapped[int] = mapped_column(SmallInteger)
factor_rules: Mapped[dict] = mapped_column(JSONB)
zero_rules: Mapped[list] = mapped_column(JSONB)
limit_description: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
sentences: Mapped[dict] = mapped_column(JSONB)
sort_order: Mapped[int] = mapped_column(SmallInteger)
class IndexScore(Base):
__tablename__ = "index_score"
region_code: Mapped[str] = mapped_column(String(10), primary_key=True)
score_date: Mapped[date] = mapped_column(Date, primary_key=True)
index_id: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
score: Mapped[int] = mapped_column(SmallInteger)
summary: Mapped[str] = mapped_column(String(100))
temp_score: Mapped[int] = mapped_column(SmallInteger)
rain_score: Mapped[int] = mapped_column(SmallInteger)
wind_score: Mapped[int] = mapped_column(SmallInteger)
humidity_score: Mapped[int] = mapped_column(SmallInteger)
air_score: Mapped[int] = mapped_column(SmallInteger)
time_score: Mapped[int] = mapped_column(SmallInteger)
zero_reason: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
notes: Mapped[dict] = mapped_column(JSONB)
computed_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
class Holiday(Base):
__tablename__ = "holiday"
holiday_date: Mapped[date] = mapped_column(Date, primary_key=True)
name: Mapped[str] = mapped_column(String(20), primary_key=True)
class Place(Base):
__tablename__ = "place"
place_id: Mapped[int] = mapped_column(Integer, primary_key=True)
region_code: Mapped[str] = mapped_column(String(10))
area: Mapped[str] = mapped_column(String(20))
name: Mapped[str] = mapped_column(String(40))
is_outdoor: Mapped[bool] = mapped_column(Boolean)
icon: Mapped[str] = mapped_column(String(30))
reason: Mapped[str] = mapped_column(String(60))
best_time: Mapped[str] = mapped_column(String(30))
sort_order: Mapped[int] = mapped_column(SmallInteger, default=0)
class Event(Base):
__tablename__ = "event"
event_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
source_id: Mapped[Optional[str]] = mapped_column(String(20), unique=True, nullable=True)
sido_code: Mapped[str] = mapped_column(String(2))
region_code: Mapped[Optional[str]] = mapped_column(String(10), nullable=True)
area: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)
name: Mapped[str] = mapped_column(String(60))
place_name: Mapped[str] = mapped_column(String(60))
icon: Mapped[str] = mapped_column(String(30), default="calendar")
start_date: Mapped[date] = mapped_column(Date)
end_date: Mapped[date] = mapped_column(Date)
is_confirmed: Mapped[bool] = mapped_column(Boolean, default=False)
source_url: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
class SolarTerm(Base):
__tablename__ = "solar_term"
term_date: Mapped[date] = mapped_column(Date, primary_key=True)
name: Mapped[str] = mapped_column(String(10))
class SeasonWeek(Base):
__tablename__ = "season_week"
year: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
week: Mapped[int] = mapped_column(SmallInteger, primary_key=True)
headline: Mapped[str] = mapped_column(String(60))
poem_lines: Mapped[list] = mapped_column(JSONB)
author: Mapped[str] = mapped_column(String(60))
class Article(Base):
__tablename__ = "article"
article_id: Mapped[int] = mapped_column(Integer, primary_key=True)
code: Mapped[str] = mapped_column(String(40), unique=True)
category: Mapped[int] = mapped_column(SmallInteger)
title: Mapped[str] = mapped_column(String(80))
read_minutes: Mapped[int] = mapped_column(SmallInteger)
icon: Mapped[str] = mapped_column(String(30))
body: Mapped[list] = mapped_column(JSONB)
show_from: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
show_until: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
sort_order: Mapped[int] = mapped_column(SmallInteger, default=0)
class Post(Base):
__tablename__ = "post"
post_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
feed_date: Mapped[date] = mapped_column(Date)
position: Mapped[int] = mapped_column(SmallInteger)
post_type: Mapped[int] = mapped_column(SmallInteger)
ref_type: Mapped[int] = mapped_column(SmallInteger, default=1)
ref_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True)
index_rank: Mapped[Optional[int]] = mapped_column(SmallInteger, nullable=True)
like_count: Mapped[int] = mapped_column(Integer, default=0)
comment_count: Mapped[int] = mapped_column(Integer, default=0)
published_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
end_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True)
deleted: Mapped[bool] = mapped_column(Boolean, default=False)
class User(Base):
__tablename__ = "users"
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
provider: Mapped[int] = mapped_column(SmallInteger, default=1)
login_id: Mapped[str] = mapped_column(String(64))
password: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
provider_uid: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
nickname: Mapped[str] = mapped_column(String(30))
character: Mapped[str] = mapped_column(String(20), default="rabbit")
color: Mapped[str] = mapped_column(String(20), default="orange")
mood: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)
status: Mapped[int] = mapped_column(SmallInteger, default=1)
token_version: Mapped[int] = mapped_column(SmallInteger, default=1)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
deleted: Mapped[bool] = mapped_column(Boolean, default=False)
class PostLike(Base):
__tablename__ = "post_like"
post_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
class PostSave(Base):
__tablename__ = "post_save"
post_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
class Comment(Base):
__tablename__ = "comment"
comment_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
post_id: Mapped[int] = mapped_column(BigInteger)
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True))
body: Mapped[str] = mapped_column(String(60))
like_count: Mapped[int] = mapped_column(Integer, default=0)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
deleted: Mapped[bool] = mapped_column(Boolean, default=False)
class CommentLike(Base):
__tablename__ = "comment_like"
comment_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())