josephrw commited on
Commit
52dd83f
·
verified ·
1 Parent(s): daf1409

Upload app/db/models.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app/db/models.py +80 -0
app/db/models.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uuid
2
+ from datetime import datetime
3
+ from sqlalchemy import String, Text, Float, DateTime, Integer, Boolean, ForeignKey, JSON
4
+ from sqlalchemy.orm import Mapped, mapped_column, relationship
5
+ from app.db.base import Base
6
+
7
+
8
+ class User(Base):
9
+ __tablename__ = "users"
10
+
11
+ id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
12
+ email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
13
+ name: Mapped[str] = mapped_column(String(255), nullable=True)
14
+ stripe_customer_id: Mapped[str] = mapped_column(String(255), nullable=True)
15
+ role: Mapped[str] = mapped_column(String(50), default="user")
16
+ is_active: Mapped[bool] = mapped_column(Boolean, default=True)
17
+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow)
18
+ updated_at: Mapped[datetime] = mapped_column(
19
+ DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow
20
+ )
21
+
22
+ runs: Mapped[list["AgentRun"]] = relationship("AgentRun", back_populates="user", lazy="selectin")
23
+ billing_events: Mapped[list["BillingEvent"]] = relationship(
24
+ "BillingEvent", back_populates="user", lazy="selectin"
25
+ )
26
+
27
+
28
+ class AgentRun(Base):
29
+ __tablename__ = "agent_runs"
30
+
31
+ id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
32
+ agent_id: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
33
+ agent_name: Mapped[str] = mapped_column(String(255), nullable=False)
34
+ query: Mapped[str] = mapped_column(Text, nullable=False)
35
+ status: Mapped[str] = mapped_column(String(50), default="pending")
36
+ result: Mapped[dict | None] = mapped_column(JSON, nullable=True)
37
+ tokens_used: Mapped[int] = mapped_column(Integer, default=0)
38
+ cost: Mapped[float] = mapped_column(Float, default=0.0)
39
+ duration_ms: Mapped[int | None] = mapped_column(Integer, nullable=True)
40
+ error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
41
+ repo_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
42
+ deployment_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
43
+ user_id: Mapped[str | None] = mapped_column(String(36), ForeignKey("users.id"), nullable=True)
44
+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow)
45
+
46
+ user: Mapped["User"] = relationship("User", back_populates="runs")
47
+
48
+
49
+ class BillingEvent(Base):
50
+ __tablename__ = "billing_events"
51
+
52
+ id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
53
+ agent_id: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
54
+ user_id: Mapped[str | None] = mapped_column(String(36), ForeignKey("users.id"), nullable=True)
55
+ stripe_event_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
56
+ amount: Mapped[float] = mapped_column(Float, default=0.0)
57
+ currency: Mapped[str] = mapped_column(String(10), default="usd")
58
+ event_type: Mapped[str] = mapped_column(String(50), default="usage")
59
+ status: Mapped[str] = mapped_column(String(50), default="pending")
60
+ metadata_: Mapped[dict | None] = mapped_column("metadata", JSON, nullable=True)
61
+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow)
62
+
63
+ user: Mapped["User"] = relationship("User", back_populates="billing_events")
64
+
65
+
66
+ class Schedule(Base):
67
+ __tablename__ = "schedules"
68
+
69
+ id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
70
+ agent_id: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
71
+ name: Mapped[str] = mapped_column(String(255), nullable=False)
72
+ query: Mapped[str] = mapped_column(Text, nullable=False)
73
+ context: Mapped[dict | None] = mapped_column(JSON, nullable=True)
74
+ cron: Mapped[str] = mapped_column(String(100), nullable=False)
75
+ is_active: Mapped[bool] = mapped_column(Boolean, default=True)
76
+ notify_email: Mapped[str | None] = mapped_column(String(255), nullable=True)
77
+ last_run_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
78
+ next_run_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
79
+ run_count: Mapped[int] = mapped_column(Integer, default=0)
80
+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow)