Files
LogHive/backend/app/models/project.py
T
2026-05-09 14:55:14 +08:00

35 lines
1.1 KiB
Python

"""Project model — represents an external service that pushes logs."""
import uuid
from datetime import datetime, timezone
from sqlalchemy import String, Boolean, DateTime, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class Project(Base):
__tablename__ = "projects"
id: Mapped[str] = mapped_column(
String(36), primary_key=True, default=lambda: str(uuid.uuid4())
)
name: Mapped[str] = mapped_column(String(128), unique=True, nullable=False)
description: Mapped[str] = mapped_column(Text, default="")
api_key: Mapped[str] = mapped_column(
String(64), unique=True, nullable=False, default=lambda: uuid.uuid4().hex
)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=lambda: datetime.now(timezone.utc),
onupdate=lambda: datetime.now(timezone.utc),
)
def __repr__(self) -> str:
return f"<Project {self.name}>"