from datetime import datetime from sqlalchemy import String, DateTime, ForeignKey, func from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base class Table(Base): __tablename__ = "tables" id: Mapped[int] = mapped_column(primary_key=True) workspace_id: Mapped[int] = mapped_column( ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, index=True ) name: Mapped[str] = mapped_column(String(255), nullable=False) description: Mapped[str] = mapped_column(String, nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now()) updated_at: Mapped[datetime] = mapped_column( DateTime, default=func.now(), onupdate=func.now() ) # Relationships workspace = relationship("Workspace", back_populates="tables") columns = relationship( "Column", back_populates="table", cascade="all, delete-orphan", order_by="Column.position", ) records = relationship( "Record", back_populates="table", cascade="all, delete-orphan" ) views = relationship("View", back_populates="table", cascade="all, delete-orphan") def __repr__(self): return f""