Files
deerflow-code/offline-backend-20260512/backend/packages/harness/deerflow/persistence/goview/models.py
T

65 lines
2.8 KiB
Python

"""ORM models for GoView projects, canvas content, and templates."""
from __future__ import annotations
from datetime import UTC, datetime
from sqlalchemy import Integer, String
from sqlalchemy.orm import Mapped, mapped_column
from deerflow.persistence.base import Base
from deerflow.persistence.types import BeijingDateTime, PortableLongText
class GoviewProjectRow(Base):
"""One GoView project card. Canvas JSON lives in ``goview_project_contents``."""
__tablename__ = "goview_projects"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
project_name: Mapped[str] = mapped_column(String(255), nullable=False)
remarks: Mapped[str | None] = mapped_column(String(512), nullable=True)
state: Mapped[int] = mapped_column(Integer, nullable=False, default=-1)
index_image: Mapped[str | None] = mapped_column(String(1024), nullable=True)
owner_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
updated_at: Mapped[datetime] = mapped_column(
BeijingDateTime(),
nullable=False,
default=lambda: datetime.now(UTC),
onupdate=lambda: datetime.now(UTC),
)
class GoviewProjectContentRow(Base):
"""The ChartEditStorage document for one project. Listed projects do not load this row."""
__tablename__ = "goview_project_contents"
project_id: Mapped[str] = mapped_column(String(64), primary_key=True)
content_json: Mapped[str] = mapped_column(PortableLongText, nullable=False)
updated_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
class GoviewTemplateRow(Base):
"""A personal template or a market template. Builtin rows are inserted only when missing."""
__tablename__ = "goview_templates"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[str | None] = mapped_column(String(512), nullable=True)
cover_image: Mapped[str | None] = mapped_column(String(1024), nullable=True)
content_json: Mapped[str] = mapped_column(PortableLongText, nullable=False)
owner_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
scope: Mapped[str] = mapped_column(String(16), nullable=False, default="personal")
is_builtin: Mapped[bool] = mapped_column(nullable=False, default=False)
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
updated_at: Mapped[datetime] = mapped_column(
BeijingDateTime(),
nullable=False,
default=lambda: datetime.now(UTC),
onupdate=lambda: datetime.now(UTC),
)