firebreak/web/app/models/grant.py
ZTatman c983a9a480 feat(web): add FastAPI service with async SQLAlchemy and Docker setup
- Add Grant model with proper typing (uuid.UUID, timezone-aware datetime)
- Add DB enum for grant_type to enforce valid values at database level
- Configure SQLAlchemy Base with datetime timezone mapping
- Harden Dockerfile: pin uv version, non-root user, security env vars
- Update docker-compose with correct healthcheck database name
- Add default database_url for Docker Compose deployment
- Add PYTHONUNBUFFERED and PYTHONDONTWRITEBYTECODE env vars
- Clean up .gitignore (merged into root)
2026-04-24 14:30:49 -04:00

32 lines
1.1 KiB
Python

import uuid
from datetime import datetime
from typing import Literal, get_args
from sqlalchemy import Enum, 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[uuid.UUID] = mapped_column(
Uuid,
primary_key=True,
server_default=func.gen_random_uuid(), # Postgres-specific (native on 13+)
)
token: Mapped[str] = mapped_column(String, unique=True, nullable=False, index=True)
created_at: Mapped[datetime] = mapped_column(server_default=func.now())
revoked_at: Mapped[datetime | None] = mapped_column(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(
Enum(*get_args(GrantType), name="grant_type_enum"),
nullable=False,
default="public",
)
recipient_email: Mapped[str | None] = mapped_column(String, nullable=True)