firebreak/web/app/models/grant.py
ZTatman 36c6231266 Add FastAPI setup with async SQLAlchemy and Grant model
- Add config.py with pydantic-settings for env configuration
- Add database.py with async SQLAlchemy (asyncpg driver)
- Add Grant model with id, token, timestamps, and grant_type
- Use Literal[public, private] for type-safe enum storage
- Add routes/links.py with Pydantic request/response models
- Update pyproject.toml dependencies
2026-04-23 17:20:16 -04:00

27 lines
1 KiB
Python

from datetime import datetime
from typing import Literal
from sqlalchemy import DateTime, String, Uuid, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
GrantType = Literal["public", "private"]
class Grant(Base):
__tablename__ = "grants"
id: Mapped[str] = mapped_column(
Uuid, primary_key=True, server_default=func.gen_random_uuid()
)
token: Mapped[str] = mapped_column(String, unique=True, nullable=False, index=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
revoked_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
repo_owner: Mapped[str] = mapped_column(String, nullable=False)
repo_name: Mapped[str] = mapped_column(String, nullable=False)
commit_sha: Mapped[str] = mapped_column(String, nullable=False)
grant_type: Mapped[GrantType] = mapped_column(
String, nullable=False, default="public"
)
recipient_email: Mapped[str | None] = mapped_column(String, nullable=True)