FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
from sqlalchemy import JSON, DateTime, Enum, ForeignKey, Integer
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
|
from app.models.enums import EnrichmentStatus
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.company import Company
|
|
|
|
|
|
class CompanyEnrichment(Base, UUIDPrimaryKeyMixin, TimestampMixin):
|
|
"""One-shot, onboarding-time company enrichment from a paid third-party
|
|
provider (NinjaPear/nubela.co) - never re-fetched on a schedule, see
|
|
app/services/enrichment_service.py. `data` holds a documented (not
|
|
DB-enforced) shape: employee_count, description, specialties,
|
|
leadership_team (each optionally carrying work_email/profile_url/bio),
|
|
funding (total_raised + rounds), competitors (name+reason), products,
|
|
recent_updates, customers. `errors` maps section name -> error message
|
|
for whichever calls failed, so a partial result is never silently
|
|
presented as complete - same transparency principle as every other
|
|
source/collector in this app."""
|
|
|
|
__tablename__ = "company_enrichments"
|
|
|
|
company_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("companies.id", ondelete="CASCADE"), unique=True, index=True
|
|
)
|
|
status: Mapped[EnrichmentStatus] = mapped_column(
|
|
Enum(EnrichmentStatus, native_enum=False, length=20), default=EnrichmentStatus.PENDING
|
|
)
|
|
data: Mapped[dict[str, Any]] = mapped_column(JSON, default=dict)
|
|
errors: Mapped[dict[str, str]] = mapped_column(JSON, default=dict)
|
|
credits_spent: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
fetched_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
|
|
company: Mapped[Company] = relationship(back_populates="enrichment")
|