Spaces:
Runtime error
Runtime error
File size: 1,898 Bytes
e80767a 69b17de e80767a 69b17de e80767a 69b17de e80767a 69b17de e80767a 69b17de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | from sqlalchemy import Column, Integer, String, Float, ForeignKey, DateTime
from sqlalchemy.orm import relationship
import datetime
from database import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
username = Column(String, unique=True, index=True)
email = Column(String, unique=True, index=True)
hashed_password = Column(String)
created_at = Column(DateTime, default=datetime.datetime.utcnow)
# Relationship to scans
scans = relationship("ScanRecord", back_populates="user")
class ScanRecord(Base):
__tablename__ = "scan_records"
id = Column(String, primary_key=True, index=True)
timestamp = Column(String, index=True) # Indexed for fast sorting
type = Column(String, index=True) # image, url, video, text
risk_score = Column(Float)
risk_level = Column(String, index=True)
threat_categories = Column(String) # We will store this as a JSON string for simplicity in SQLite
raw_text_extracted = Column(String, nullable=True)
behavioral_profile = Column(String, nullable=True) # Stored as JSON string
source = Column(String, nullable=True) # E.g. 'WhatsApp', 'Email', etc.
user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
# Relationships
user = relationship("User", back_populates="scans")
explanations = relationship("ScanExplanation", back_populates="scan_record", cascade="all, delete-orphan")
class ScanExplanation(Base):
__tablename__ = "scan_explanations"
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
scan_id = Column(String, ForeignKey("scan_records.id"))
feature = Column(String)
description = Column(String)
risk_contribution = Column(Float)
# Relationship back to parent
scan_record = relationship("ScanRecord", back_populates="explanations")
|