Files
habit-tracker/migrations/versions/0013_journal_category_template.py
shinalokandClaude Sonnet 5 c466cc6639 journal: multi-select emotions and per-category writing templates
- Mood switches from a single enum column to a many-to-many
  JournalEntryMood table so an entry can carry several feelings at
  once; the vocabulary is trimmed to 9 named emotions (dropped the
  overlapping satisfaction scale) with unified noun-style labels.
- Categories can define a content_template that pre-fills the "new
  entry" textarea when selected (only if the user hasn't started
  typing), seeded with a Story/Feelings/Decisions/Insights/Actions
  reflection template on the default "일상" category.
- Fixes a real attribute-injection bug found while building the
  template feature: Jinja's built-in |tojson filter doesn't escape
  double quotes, which breaks a double-quoted x-data="..." attribute
  when the JSON payload contains one; added |forceescape and a
  regression test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-04 19:12:59 +09:00

59 lines
1.8 KiB
Python

"""add content_template to journal_category, seed the default 일상 category's template
Revision ID: 0013_journal_category_template
Revises: 0012_remove_satisfaction_moods
Create Date: 2026-08-04
카테고리별로 "새 기록 쓰기" 폼의 내용칸을 미리 채워주는 틀(예: Story/Feelings/Decisions/
Insights/Actions 회고 양식)을 지정할 수 있게 한다. 이미 존재하는 "일상" 카테고리에는 이 틀을
바로 채워 넣는다(새로 자동 생성되는 "일상"은 ensure_default_category가 채운다).
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0013_journal_category_template"
down_revision: Union[str, None] = "0012_remove_satisfaction_moods"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
DAILY_TEMPLATE = """**1. Story : 오늘 무슨 일이 있었나요?**
-
**2. Feelings : 오늘 들었던 생각과 나의 감정은?**
-
**3. Decisions : 오늘 내가 내린 결정이 있나요?**
-
**4. Insights : 나에 대해 새롭게 알게된 사실이 있나요?**
-
→ 나에 대한 인사이트는 메타인지를 키워주는 **소중한 기록**입니다. 꼭 보관하세요.
**5. Actions : 내가 다음에 할 행동은 무엇인가요?**
- """
def upgrade() -> None:
op.add_column("journal_category", sa.Column("content_template", sa.Text(), nullable=True))
journal_category = sa.table(
"journal_category", sa.column("name", sa.String), sa.column("content_template", sa.Text)
)
op.execute(
journal_category.update()
.where(journal_category.c.name == "일상")
.values(content_template=DAILY_TEMPLATE)
)
def downgrade() -> None:
op.drop_column("journal_category", "content_template")