37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""SavedView model — tenant-scoped, user-scoped saved view configurations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from typing import Any
|
|
|
|
from sqlalchemy import ForeignKey, Index, String, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.db import Base, TenantMixin
|
|
|
|
|
|
class SavedView(Base, TenantMixin):
|
|
"""Saved view — reusable view configuration (filter+sort+group+viewMode+folder) for list views."""
|
|
|
|
__tablename__ = "saved_views"
|
|
__table_args__ = (
|
|
UniqueConstraint("tenant_id", "user_id", "entity_type", "name", name="uq_saved_views_tenant_user_entity_name"),
|
|
Index("ix_saved_views_tenant_user", "tenant_id", "user_id"),
|
|
Index("ix_saved_views_tenant_entity", "tenant_id", "entity_type"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
entity_type: Mapped[str] = mapped_column(
|
|
String(50), nullable=False
|
|
) # contacts, mail, calendar, dms
|
|
view_config: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
|
)
|