Spaces:
Running
Running
Download backend/app/db_models.py from HeshamXOR/MalwareGuard: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/spaces/HeshamXOR/MalwareGuard/resolve/main/backend/app/db_models.py
- Command line
-
hf download hf://spaces/HeshamXOR/MalwareGuard/backend/app/db_models.py
-
curl -L -o db_models.py https://huggingface.co/spaces/HeshamXOR/MalwareGuard/resolve/main/backend/app/db_models.py
2.28 kB
| """SQLAlchemy models for users and scan metadata.""" | |
| from datetime import datetime | |
| from sqlalchemy import Boolean, Column, DateTime, Float, ForeignKey, Integer, String, Text | |
| from sqlalchemy.orm import relationship | |
| from .database import Base | |
| class User(Base): | |
| __tablename__ = "users" | |
| id = Column(Integer, primary_key=True, index=True) | |
| clerk_user_id = Column(String(128), unique=True, index=True, nullable=True) | |
| email = Column(String(255), unique=True, index=True, nullable=False) | |
| password_hash = Column(String(255), nullable=False) | |
| display_name = Column(String(120), nullable=True) | |
| role = Column(String(32), default="user", nullable=False) | |
| tier = Column(String(32), default="free", nullable=False) | |
| is_active = Column(Boolean, default=True, nullable=False) | |
| created_at = Column(DateTime, default=datetime.utcnow, nullable=False) | |
| updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False) | |
| scans = relationship("ScanEvent", back_populates="user") | |
| class ScanEvent(Base): | |
| __tablename__ = "scan_events" | |
| id = Column(Integer, primary_key=True, index=True) | |
| user_id = Column(Integer, ForeignKey("users.id"), nullable=True, index=True) | |
| anonymous_key = Column(String(64), nullable=True, index=True) | |
| scan_type = Column(String(32), nullable=False, index=True) | |
| target = Column(Text, nullable=True) | |
| sha256 = Column(String(64), nullable=True, index=True) | |
| verdict = Column(String(64), nullable=True) | |
| confidence = Column(Float, nullable=True) | |
| created_at = Column(DateTime, default=datetime.utcnow, nullable=False, index=True) | |
| user = relationship("User", back_populates="scans") | |
| class AuditLog(Base): | |
| __tablename__ = "audit_logs" | |
| id = Column(Integer, primary_key=True, index=True) | |
| actor_user_id = Column(Integer, ForeignKey("users.id"), nullable=True, index=True) | |
| action = Column(String(64), nullable=False, index=True) | |
| target_type = Column(String(64), nullable=False) | |
| target_id = Column(String(64), nullable=True) | |
| summary = Column(Text, nullable=False) | |
| created_at = Column(DateTime, default=datetime.utcnow, nullable=False, index=True) | |
| actor = relationship("User") | |