demo table
unknown
python
10 months ago
2.2 kB
8
Indexable
from sqlalchemy import Column, ForeignKey, Integer, Float, String, Enum, Text, UUID
from sqlalchemy.orm import declarative_base, Mapped, mapped_column, relationship
import uuid
Base = declarative_base()
class GroupBudget(Base):
__tablename__ = 'group_budget'
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
organization_id: Mapped[int] = mapped_column(Integer, ForeignKey('organization.id'), nullable=False)
remaining_budget: Mapped[float] = mapped_column(Float, nullable=False)
organization = relationship("Organization", back_populates="group_budgets")
class QARequestDetails(Base):
__tablename__ = 'qa_request_details'
request_id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
trail_numbers: Mapped[int] = mapped_column(Integer, nullable=False)
proxy_server_request_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), default=uuid.uuid4, nullable=False)
status: Mapped[str] = mapped_column(Enum('pending', 'in_progress', 'completed', 'failed', name='status_enum'), nullable=False)
type: Mapped[str] = mapped_column(Enum('type1', 'type2', 'type3', name='type_enum'), nullable=False)
request_payload: Mapped[str] = mapped_column(Text, nullable=True)
request_response: Mapped[str] = mapped_column(Text, nullable=True)
user_requests = relationship("UserRequest", back_populates="qa_request_details")
class UserRequest(Base):
__tablename__ = 'user_request'
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[int] = mapped_column(Integer, ForeignKey('user.id'), nullable=False)
request_id: Mapped[int] = mapped_column(Integer, ForeignKey('qa_request_details.request_id'), nullable=False)
user = relationship("User", back_populates="user_requests")
qa_request_details = relationship("QARequestDetails", back_populates="user_requests")
# Example to create tables in the database (assuming engine is defined)
if __name__ == "__main__":
from sqlalchemy import create_engine
# Replace 'sqlite:///example.db' with your database URL
engine = create_engine('sqlite:///example.db')
Base.metadata.create_all(engine)Editor is loading...
Leave a Comment