42 lines
2.6 KiB
Python
42 lines
2.6 KiB
Python
from datetime import datetime
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy import Integer, String, Boolean, DateTime, Text, ForeignKey
|
|
from app.core.database import Base
|
|
|
|
class Board(Base):
|
|
__tablename__ = "board"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
code: Mapped[str] = mapped_column(String(50), unique=True, index=True, nullable=False) # 예: "notices", "free"
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False) # 예: "공지사항"
|
|
description: Mapped[str | None] = mapped_column(String(255))
|
|
is_public: Mapped[bool] = mapped_column(Boolean, default=True) # 공개 여부
|
|
allow_comment: Mapped[bool] = mapped_column(Boolean, default=True) # 댓글 허용
|
|
use_attachment: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
class BoardPost(Base):
|
|
__tablename__ = "board_post"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
board_id: Mapped[int] = mapped_column(ForeignKey("board.id", ondelete="CASCADE"), index=True, nullable=False)
|
|
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
|
content: Mapped[str] = mapped_column(Text, nullable=False)
|
|
author_id: Mapped[int | None] = mapped_column(Integer, nullable=True) # 일반 유저 id(선택)
|
|
is_notice: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
is_pinned: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
view_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
class BoardComment(Base):
|
|
__tablename__ = "board_comment"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
post_id: Mapped[int] = mapped_column(ForeignKey("board_post.id", ondelete="CASCADE"), index=True, nullable=False)
|
|
author_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
content: Mapped[str] = mapped_column(Text, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|