Files
guarddog-nexus/guarddog_nexus/db/models.py
Marker689 8726b65808 refactor: реструктуризация — core/, db/, routes/, web/
guarddog_nexus/
├── core/          scanner, harvester, nexus, llm
├── db/            engine, models, queries
├── routes/        webhooks, api_*, web
└── web/           templates + static

- 11 файлов перемещено (git mv — сохранена история)
- Все импорты обновлены (~15 файлов)
- main.py, tests — исправлены пути
- 50/50 тестов, ruff clean
2026-05-10 07:17:41 +03:00

57 lines
2.2 KiB
Python

"""SQLAlchemy ORM models."""
import datetime
from enum import Enum
from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from guarddog_nexus.db.engine import Base
class ScanStatus(str, Enum):
PENDING = "pending"
SCANNING = "scanning"
COMPLETED = "completed"
FAILED = "failed"
class Scan(Base):
__tablename__ = "scans"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
package_name: Mapped[str] = mapped_column(String(255), nullable=False)
package_version: Mapped[str] = mapped_column(String(255), nullable=False)
ecosystem: Mapped[str] = mapped_column(String(50), nullable=False, default="pypi")
repository: Mapped[str] = mapped_column(String(255), nullable=False)
nexus_asset_url: Mapped[str] = mapped_column(Text, nullable=False)
sha256: Mapped[str | None] = mapped_column(String(64), nullable=True)
status: Mapped[str] = mapped_column(
String(20), nullable=False, default=ScanStatus.PENDING.value
)
total_findings: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
flagged: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
started_at: Mapped[datetime.datetime] = mapped_column(
DateTime, nullable=False, default=func.now()
)
finished_at: Mapped[datetime.datetime | None] = mapped_column(DateTime, nullable=True)
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
findings: Mapped[list["Finding"]] = relationship(
"Finding", back_populates="scan", cascade="all, delete-orphan"
)
class Finding(Base):
__tablename__ = "findings"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
scan_id: Mapped[int] = mapped_column(Integer, ForeignKey("scans.id"), nullable=False)
data: Mapped[dict] = mapped_column(JSON, nullable=False)
report: Mapped[dict | None] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime.datetime] = mapped_column(
DateTime, nullable=False, default=func.now()
)
scan: Mapped["Scan"] = relationship("Scan", back_populates="findings")