Update Python version requirements and fix compatibility issues
- Bump minimum Python version from 3.11 to 3.13 across all apps - Add Python 3.11-3.13 test matrix to CLI workflow - Document Python 3.11+ requirement in .env.example - Fix Starlette Broadcast removal with in-process fallback implementation - Add _InProcessBroadcast class for tests when Starlette Broadcast is unavailable - Refactor API key validators to read live settings instead of cached values - Update database models with explicit
This commit is contained in:
@@ -4,9 +4,10 @@ from .job import Job
|
||||
from .miner import Miner
|
||||
from .job_receipt import JobReceipt
|
||||
from .marketplace import MarketplaceOffer, MarketplaceBid
|
||||
from .user import User, Wallet
|
||||
from .user import User, Wallet, Transaction, UserSession
|
||||
from .payment import JobPayment, PaymentEscrow
|
||||
from .gpu_marketplace import GPURegistry, GPUBooking, GPUReview
|
||||
from .gpu_marketplace import GPURegistry, ConsumerGPUProfile, EdgeGPUMetrics, GPUBooking, GPUReview
|
||||
from .agent import AIAgentWorkflow, AgentStep, AgentExecution, AgentStepExecution, AgentMarketplace
|
||||
|
||||
__all__ = [
|
||||
"Job",
|
||||
@@ -16,9 +17,18 @@ __all__ = [
|
||||
"MarketplaceBid",
|
||||
"User",
|
||||
"Wallet",
|
||||
"Transaction",
|
||||
"UserSession",
|
||||
"JobPayment",
|
||||
"PaymentEscrow",
|
||||
"GPURegistry",
|
||||
"ConsumerGPUProfile",
|
||||
"EdgeGPUMetrics",
|
||||
"GPUBooking",
|
||||
"GPUReview",
|
||||
"AIAgentWorkflow",
|
||||
"AgentStep",
|
||||
"AgentExecution",
|
||||
"AgentStepExecution",
|
||||
"AgentMarketplace",
|
||||
]
|
||||
|
||||
289
apps/coordinator-api/src/app/domain/agent.py
Normal file
289
apps/coordinator-api/src/app/domain/agent.py
Normal file
@@ -0,0 +1,289 @@
|
||||
"""
|
||||
AI Agent Domain Models for Verifiable AI Agent Orchestration
|
||||
Implements SQLModel definitions for agent workflows, steps, and execution tracking
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, List, Any
|
||||
from uuid import uuid4
|
||||
from enum import Enum
|
||||
|
||||
from sqlmodel import SQLModel, Field, Column, JSON
|
||||
from sqlalchemy import DateTime
|
||||
|
||||
|
||||
class AgentStatus(str, Enum):
|
||||
"""Agent execution status enumeration"""
|
||||
PENDING = "pending"
|
||||
RUNNING = "running"
|
||||
COMPLETED = "completed"
|
||||
FAILED = "failed"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class VerificationLevel(str, Enum):
|
||||
"""Verification level for agent execution"""
|
||||
BASIC = "basic"
|
||||
FULL = "full"
|
||||
ZERO_KNOWLEDGE = "zero-knowledge"
|
||||
|
||||
|
||||
class StepType(str, Enum):
|
||||
"""Agent step type enumeration"""
|
||||
INFERENCE = "inference"
|
||||
TRAINING = "training"
|
||||
DATA_PROCESSING = "data_processing"
|
||||
VERIFICATION = "verification"
|
||||
CUSTOM = "custom"
|
||||
|
||||
|
||||
class AIAgentWorkflow(SQLModel, table=True):
|
||||
"""Definition of an AI agent workflow"""
|
||||
|
||||
__tablename__ = "ai_agent_workflows"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"agent_{uuid4().hex[:8]}", primary_key=True)
|
||||
owner_id: str = Field(index=True)
|
||||
name: str = Field(max_length=100)
|
||||
description: str = Field(default="")
|
||||
|
||||
# Workflow specification
|
||||
steps: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON, nullable=False))
|
||||
dependencies: Dict[str, List[str]] = Field(default_factory=dict, sa_column=Column(JSON, nullable=False))
|
||||
|
||||
# Execution constraints
|
||||
max_execution_time: int = Field(default=3600) # seconds
|
||||
max_cost_budget: float = Field(default=0.0)
|
||||
|
||||
# Verification requirements
|
||||
requires_verification: bool = Field(default=True)
|
||||
verification_level: VerificationLevel = Field(default=VerificationLevel.BASIC)
|
||||
|
||||
# Metadata
|
||||
tags: str = Field(default="") # JSON string of tags
|
||||
version: str = Field(default="1.0.0")
|
||||
is_public: bool = Field(default=False)
|
||||
|
||||
# Timestamps
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class AgentStep(SQLModel, table=True):
|
||||
"""Individual step in an AI agent workflow"""
|
||||
|
||||
__tablename__ = "agent_steps"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"step_{uuid4().hex[:8]}", primary_key=True)
|
||||
workflow_id: str = Field(index=True)
|
||||
step_order: int = Field(default=0)
|
||||
|
||||
# Step specification
|
||||
name: str = Field(max_length=100)
|
||||
step_type: StepType = Field(default=StepType.INFERENCE)
|
||||
model_requirements: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
|
||||
input_mappings: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
|
||||
output_mappings: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
|
||||
|
||||
# Execution parameters
|
||||
timeout_seconds: int = Field(default=300)
|
||||
retry_policy: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON))
|
||||
max_retries: int = Field(default=3)
|
||||
|
||||
# Verification
|
||||
requires_proof: bool = Field(default=False)
|
||||
verification_level: VerificationLevel = Field(default=VerificationLevel.BASIC)
|
||||
|
||||
# Dependencies
|
||||
depends_on: str = Field(default="") # JSON string of step IDs
|
||||
|
||||
# Timestamps
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class AgentExecution(SQLModel, table=True):
|
||||
"""Tracks execution state of AI agent workflows"""
|
||||
|
||||
__tablename__ = "agent_executions"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"exec_{uuid4().hex[:10]}", primary_key=True)
|
||||
workflow_id: str = Field(index=True)
|
||||
client_id: str = Field(index=True)
|
||||
|
||||
# Execution state
|
||||
status: AgentStatus = Field(default=AgentStatus.PENDING)
|
||||
current_step: int = Field(default=0)
|
||||
step_states: Dict[str, Any] = Field(default_factory=dict, sa_column=Column(JSON, nullable=False))
|
||||
|
||||
# Results and verification
|
||||
final_result: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
execution_receipt: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
verification_proof: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
|
||||
# Error handling
|
||||
error_message: Optional[str] = Field(default=None)
|
||||
failed_step: Optional[str] = Field(default=None)
|
||||
|
||||
# Timing and cost
|
||||
started_at: Optional[datetime] = Field(default=None)
|
||||
completed_at: Optional[datetime] = Field(default=None)
|
||||
total_execution_time: Optional[float] = Field(default=None) # seconds
|
||||
total_cost: float = Field(default=0.0)
|
||||
|
||||
# Progress tracking
|
||||
total_steps: int = Field(default=0)
|
||||
completed_steps: int = Field(default=0)
|
||||
|
||||
# Timestamps
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class AgentStepExecution(SQLModel, table=True):
|
||||
"""Tracks execution of individual steps within an agent workflow"""
|
||||
|
||||
__tablename__ = "agent_step_executions"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"step_exec_{uuid4().hex[:10]}", primary_key=True)
|
||||
execution_id: str = Field(index=True)
|
||||
step_id: str = Field(index=True)
|
||||
|
||||
# Execution state
|
||||
status: AgentStatus = Field(default=AgentStatus.PENDING)
|
||||
|
||||
# Step-specific data
|
||||
input_data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
output_data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
|
||||
# Performance metrics
|
||||
execution_time: Optional[float] = Field(default=None) # seconds
|
||||
gpu_accelerated: bool = Field(default=False)
|
||||
memory_usage: Optional[float] = Field(default=None) # MB
|
||||
|
||||
# Verification
|
||||
step_proof: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
||||
verification_status: Optional[str] = Field(default=None)
|
||||
|
||||
# Error handling
|
||||
error_message: Optional[str] = Field(default=None)
|
||||
retry_count: int = Field(default=0)
|
||||
|
||||
# Timing
|
||||
started_at: Optional[datetime] = Field(default=None)
|
||||
completed_at: Optional[datetime] = Field(default=None)
|
||||
|
||||
# Timestamps
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class AgentMarketplace(SQLModel, table=True):
|
||||
"""Marketplace for AI agent workflows"""
|
||||
|
||||
__tablename__ = "agent_marketplace"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"amkt_{uuid4().hex[:8]}", primary_key=True)
|
||||
workflow_id: str = Field(index=True)
|
||||
|
||||
# Marketplace metadata
|
||||
title: str = Field(max_length=200)
|
||||
description: str = Field(default="")
|
||||
tags: str = Field(default="") # JSON string of tags
|
||||
category: str = Field(default="general")
|
||||
|
||||
# Pricing
|
||||
execution_price: float = Field(default=0.0)
|
||||
subscription_price: float = Field(default=0.0)
|
||||
pricing_model: str = Field(default="pay-per-use") # pay-per-use, subscription, freemium
|
||||
|
||||
# Reputation and usage
|
||||
rating: float = Field(default=0.0)
|
||||
total_executions: int = Field(default=0)
|
||||
successful_executions: int = Field(default=0)
|
||||
average_execution_time: Optional[float] = Field(default=None)
|
||||
|
||||
# Access control
|
||||
is_public: bool = Field(default=True)
|
||||
authorized_users: str = Field(default="") # JSON string of authorized users
|
||||
|
||||
# Performance metrics
|
||||
last_execution_status: Optional[AgentStatus] = Field(default=None)
|
||||
last_execution_at: Optional[datetime] = Field(default=None)
|
||||
|
||||
# Timestamps
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
# Request/Response Models for API
|
||||
class AgentWorkflowCreate(SQLModel):
|
||||
"""Request model for creating agent workflows"""
|
||||
name: str = Field(max_length=100)
|
||||
description: str = Field(default="")
|
||||
steps: Dict[str, Any]
|
||||
dependencies: Dict[str, List[str]] = Field(default_factory=dict)
|
||||
max_execution_time: int = Field(default=3600)
|
||||
max_cost_budget: float = Field(default=0.0)
|
||||
requires_verification: bool = Field(default=True)
|
||||
verification_level: VerificationLevel = Field(default=VerificationLevel.BASIC)
|
||||
tags: List[str] = Field(default_factory=list)
|
||||
is_public: bool = Field(default=False)
|
||||
|
||||
|
||||
class AgentWorkflowUpdate(SQLModel):
|
||||
"""Request model for updating agent workflows"""
|
||||
name: Optional[str] = Field(default=None, max_length=100)
|
||||
description: Optional[str] = Field(default=None)
|
||||
steps: Optional[Dict[str, Any]] = Field(default=None)
|
||||
dependencies: Optional[Dict[str, List[str]]] = Field(default=None)
|
||||
max_execution_time: Optional[int] = Field(default=None)
|
||||
max_cost_budget: Optional[float] = Field(default=None)
|
||||
requires_verification: Optional[bool] = Field(default=None)
|
||||
verification_level: Optional[VerificationLevel] = Field(default=None)
|
||||
tags: Optional[List[str]] = Field(default=None)
|
||||
is_public: Optional[bool] = Field(default=None)
|
||||
|
||||
|
||||
class AgentExecutionRequest(SQLModel):
|
||||
"""Request model for executing agent workflows"""
|
||||
workflow_id: str
|
||||
inputs: Dict[str, Any]
|
||||
verification_level: Optional[VerificationLevel] = Field(default=VerificationLevel.BASIC)
|
||||
max_execution_time: Optional[int] = Field(default=None)
|
||||
max_cost_budget: Optional[float] = Field(default=None)
|
||||
|
||||
|
||||
class AgentExecutionResponse(SQLModel):
|
||||
"""Response model for agent execution"""
|
||||
execution_id: str
|
||||
workflow_id: str
|
||||
status: AgentStatus
|
||||
current_step: int
|
||||
total_steps: int
|
||||
started_at: Optional[datetime]
|
||||
estimated_completion: Optional[datetime]
|
||||
current_cost: float
|
||||
estimated_total_cost: Optional[float]
|
||||
|
||||
|
||||
class AgentExecutionStatus(SQLModel):
|
||||
"""Response model for execution status"""
|
||||
execution_id: str
|
||||
workflow_id: str
|
||||
status: AgentStatus
|
||||
current_step: int
|
||||
total_steps: int
|
||||
step_states: Dict[str, Any]
|
||||
final_result: Optional[Dict[str, Any]]
|
||||
error_message: Optional[str]
|
||||
started_at: Optional[datetime]
|
||||
completed_at: Optional[datetime]
|
||||
total_execution_time: Optional[float]
|
||||
total_cost: float
|
||||
verification_proof: Optional[Dict[str, Any]]
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -10,9 +11,20 @@ from sqlalchemy import Column, JSON
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class GPUArchitecture(str, Enum):
|
||||
TURING = "turing" # RTX 20 series
|
||||
AMPERE = "ampere" # RTX 30 series
|
||||
ADA_LOVELACE = "ada_lovelace" # RTX 40 series
|
||||
PASCAL = "pascal" # GTX 10 series
|
||||
VOLTA = "volta" # Titan V, Tesla V100
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class GPURegistry(SQLModel, table=True):
|
||||
"""Registered GPUs available in the marketplace."""
|
||||
|
||||
__tablename__ = "gpu_registry"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"gpu_{uuid4().hex[:8]}", primary_key=True)
|
||||
miner_id: str = Field(index=True)
|
||||
model: str = Field(index=True)
|
||||
@@ -27,9 +39,92 @@ class GPURegistry(SQLModel, table=True):
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, index=True)
|
||||
|
||||
|
||||
class ConsumerGPUProfile(SQLModel, table=True):
|
||||
"""Consumer GPU optimization profiles for edge computing"""
|
||||
__tablename__ = "consumer_gpu_profiles"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"cgp_{uuid4().hex[:8]}", primary_key=True)
|
||||
gpu_model: str = Field(index=True)
|
||||
architecture: GPUArchitecture = Field(default=GPUArchitecture.UNKNOWN)
|
||||
consumer_grade: bool = Field(default=True)
|
||||
edge_optimized: bool = Field(default=False)
|
||||
|
||||
# Hardware specifications
|
||||
cuda_cores: Optional[int] = Field(default=None)
|
||||
memory_gb: Optional[int] = Field(default=None)
|
||||
memory_bandwidth_gbps: Optional[float] = Field(default=None)
|
||||
tensor_cores: Optional[int] = Field(default=None)
|
||||
base_clock_mhz: Optional[int] = Field(default=None)
|
||||
boost_clock_mhz: Optional[int] = Field(default=None)
|
||||
|
||||
# Edge optimization metrics
|
||||
power_consumption_w: Optional[float] = Field(default=None)
|
||||
thermal_design_power_w: Optional[float] = Field(default=None)
|
||||
noise_level_db: Optional[float] = Field(default=None)
|
||||
|
||||
# Performance characteristics
|
||||
fp32_tflops: Optional[float] = Field(default=None)
|
||||
fp16_tflops: Optional[float] = Field(default=None)
|
||||
int8_tops: Optional[float] = Field(default=None)
|
||||
|
||||
# Edge-specific optimizations
|
||||
low_latency_mode: bool = Field(default=False)
|
||||
mobile_optimized: bool = Field(default=False)
|
||||
thermal_throttling_resistance: Optional[float] = Field(default=None)
|
||||
|
||||
# Compatibility flags
|
||||
supported_cuda_versions: list = Field(default_factory=list, sa_column=Column(JSON, nullable=True))
|
||||
supported_tensorrt_versions: list = Field(default_factory=list, sa_column=Column(JSON, nullable=True))
|
||||
supported_ollama_models: list = Field(default_factory=list, sa_column=Column(JSON, nullable=True))
|
||||
|
||||
# Pricing and availability
|
||||
market_price_usd: Optional[float] = Field(default=None)
|
||||
edge_premium_multiplier: float = Field(default=1.0)
|
||||
availability_score: float = Field(default=1.0)
|
||||
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
|
||||
|
||||
class EdgeGPUMetrics(SQLModel, table=True):
|
||||
"""Real-time edge GPU performance metrics"""
|
||||
__tablename__ = "edge_gpu_metrics"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"egm_{uuid4().hex[:8]}", primary_key=True)
|
||||
gpu_id: str = Field(foreign_key="gpuregistry.id")
|
||||
|
||||
# Latency metrics
|
||||
network_latency_ms: float = Field()
|
||||
compute_latency_ms: float = Field()
|
||||
total_latency_ms: float = Field()
|
||||
|
||||
# Resource utilization
|
||||
gpu_utilization_percent: float = Field()
|
||||
memory_utilization_percent: float = Field()
|
||||
power_draw_w: float = Field()
|
||||
temperature_celsius: float = Field()
|
||||
|
||||
# Edge-specific metrics
|
||||
thermal_throttling_active: bool = Field(default=False)
|
||||
power_limit_active: bool = Field(default=False)
|
||||
clock_throttling_active: bool = Field(default=False)
|
||||
|
||||
# Geographic and network info
|
||||
region: str = Field()
|
||||
city: Optional[str] = Field(default=None)
|
||||
isp: Optional[str] = Field(default=None)
|
||||
connection_type: Optional[str] = Field(default=None)
|
||||
|
||||
timestamp: datetime = Field(default_factory=datetime.utcnow, index=True)
|
||||
|
||||
|
||||
class GPUBooking(SQLModel, table=True):
|
||||
"""Active and historical GPU bookings."""
|
||||
|
||||
__tablename__ = "gpu_bookings"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"bk_{uuid4().hex[:10]}", primary_key=True)
|
||||
gpu_id: str = Field(index=True)
|
||||
client_id: str = Field(default="", index=True)
|
||||
@@ -44,7 +139,9 @@ class GPUBooking(SQLModel, table=True):
|
||||
|
||||
class GPUReview(SQLModel, table=True):
|
||||
"""Reviews for GPUs."""
|
||||
|
||||
__tablename__ = "gpu_reviews"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: f"rv_{uuid4().hex[:10]}", primary_key=True)
|
||||
gpu_id: str = Field(index=True)
|
||||
user_id: str = Field(default="")
|
||||
|
||||
@@ -11,6 +11,7 @@ from sqlmodel import Field, SQLModel
|
||||
|
||||
class Job(SQLModel, table=True):
|
||||
__tablename__ = "job"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True, index=True)
|
||||
client_id: str = Field(index=True)
|
||||
|
||||
@@ -8,6 +8,9 @@ from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class JobReceipt(SQLModel, table=True):
|
||||
__tablename__ = "jobreceipt"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True, index=True)
|
||||
job_id: str = Field(index=True, foreign_key="job.id")
|
||||
receipt_id: str = Field(index=True)
|
||||
|
||||
@@ -9,6 +9,9 @@ from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class MarketplaceOffer(SQLModel, table=True):
|
||||
__tablename__ = "marketplaceoffer"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True)
|
||||
provider: str = Field(index=True)
|
||||
capacity: int = Field(default=0, nullable=False)
|
||||
@@ -27,6 +30,9 @@ class MarketplaceOffer(SQLModel, table=True):
|
||||
|
||||
|
||||
class MarketplaceBid(SQLModel, table=True):
|
||||
__tablename__ = "marketplacebid"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True)
|
||||
provider: str = Field(index=True)
|
||||
capacity: int = Field(default=0, nullable=False)
|
||||
|
||||
@@ -8,6 +8,9 @@ from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Miner(SQLModel, table=True):
|
||||
__tablename__ = "miner"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(primary_key=True, index=True)
|
||||
region: Optional[str] = Field(default=None, index=True)
|
||||
capabilities: dict = Field(default_factory=dict, sa_column=Column(JSON, nullable=False))
|
||||
|
||||
@@ -15,6 +15,7 @@ class JobPayment(SQLModel, table=True):
|
||||
"""Payment record for a job"""
|
||||
|
||||
__tablename__ = "job_payments"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True, index=True)
|
||||
job_id: str = Field(index=True)
|
||||
@@ -52,6 +53,7 @@ class PaymentEscrow(SQLModel, table=True):
|
||||
"""Escrow record for holding payments"""
|
||||
|
||||
__tablename__ = "payment_escrows"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(default_factory=lambda: uuid4().hex, primary_key=True, index=True)
|
||||
payment_id: str = Field(index=True)
|
||||
|
||||
@@ -10,6 +10,9 @@ from typing import Optional, List
|
||||
|
||||
class User(SQLModel, table=True):
|
||||
"""User model"""
|
||||
__tablename__ = "users"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(primary_key=True)
|
||||
email: str = Field(unique=True, index=True)
|
||||
username: str = Field(unique=True, index=True)
|
||||
@@ -25,6 +28,9 @@ class User(SQLModel, table=True):
|
||||
|
||||
class Wallet(SQLModel, table=True):
|
||||
"""Wallet model for storing user balances"""
|
||||
__tablename__ = "wallets"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
user_id: str = Field(foreign_key="user.id")
|
||||
address: str = Field(unique=True, index=True)
|
||||
@@ -39,6 +45,9 @@ class Wallet(SQLModel, table=True):
|
||||
|
||||
class Transaction(SQLModel, table=True):
|
||||
"""Transaction model"""
|
||||
__tablename__ = "transactions"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: str = Field(primary_key=True)
|
||||
user_id: str = Field(foreign_key="user.id")
|
||||
wallet_id: Optional[int] = Field(foreign_key="wallet.id")
|
||||
@@ -58,6 +67,9 @@ class Transaction(SQLModel, table=True):
|
||||
|
||||
class UserSession(SQLModel, table=True):
|
||||
"""User session model"""
|
||||
__tablename__ = "user_sessions"
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
user_id: str = Field(foreign_key="user.id")
|
||||
token: str = Field(unique=True, index=True)
|
||||
|
||||
Reference in New Issue
Block a user