mirror of
https://github.com/olegvodyanov/docbot.git
synced 2025-12-19 23:57:05 +03:00
include db python files
This commit is contained in:
parent
4492c03590
commit
2c6afb3499
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,5 +5,6 @@
|
||||
alembic.ini
|
||||
alembic/
|
||||
db/
|
||||
!src/db
|
||||
__pycache__
|
||||
src/docbot/conversations.pkl
|
||||
0
src/db/__init__.py
Normal file
0
src/db/__init__.py
Normal file
84
src/db/models.py
Normal file
84
src/db/models.py
Normal file
@ -0,0 +1,84 @@
|
||||
from sqlalchemy import Column, String, DateTime, ARRAY, Boolean, ForeignKey, Integer, Table, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
import uuid
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class SessionCode(Base):
|
||||
__tablename__ = "session_codes"
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
code = Column(String(8), unique=True, nullable=False)
|
||||
telegram_id = Column(Integer, nullable=False)
|
||||
sent_at = Column(DateTime, nullable=False)
|
||||
consulted_at = Column(DateTime, nullable=True)
|
||||
doctor_id = Column(UUID, ForeignKey("doctors.id"))
|
||||
form_link_response = Column(String, nullable=True)
|
||||
|
||||
|
||||
class Admins(Base):
|
||||
__tablename__ = "admins"
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
telegram_id = Column(Integer, unique=True, nullable=False)
|
||||
created_at = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
class Doctors(Base):
|
||||
__tablename__ = "doctors"
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
telegram_id = Column(Integer, unique=True, nullable=False)
|
||||
code = Column(String(8), unique=True, nullable=False)
|
||||
name = Column(String, nullable=False)
|
||||
available_formats = Column(ARRAY(String), nullable=True)
|
||||
is_active = Column(Boolean, default=False, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
referral_code_id = Column(Integer, ForeignKey("referral_codes.id"), nullable=False)
|
||||
specialties = Column(ARRAY(String), nullable=False, default=list)
|
||||
|
||||
referral = relationship("ReferralCode", back_populates="doctor")
|
||||
session_codes = relationship("SessionCode")
|
||||
form_links = relationship("FormLink", back_populates="doctor", cascade="all, delete-orphan")
|
||||
payment_methods = relationship("PaymentMethod", back_populates="doctor", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Doctors(telegram_id={self.telegram_id!r})>"
|
||||
|
||||
|
||||
class ReferralCode(Base):
|
||||
__tablename__ = "referral_codes"
|
||||
id = Column(Integer, primary_key=True)
|
||||
code = Column(String, unique=True, nullable=False)
|
||||
is_used = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
used_at = Column(DateTime, nullable=True)
|
||||
doctor = relationship("Doctors", back_populates="referral", uselist=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ReferralCode(code={self.code!r}, is_used={self.is_used})>"
|
||||
|
||||
|
||||
class FormLink(Base):
|
||||
__tablename__ = "form_links"
|
||||
id = Column(Integer, primary_key=True)
|
||||
doctor_id = Column(UUID(as_uuid=True), ForeignKey("doctors.id", ondelete="CASCADE"), nullable=False)
|
||||
url = Column(String, nullable=False)
|
||||
label = Column(String, nullable=True)
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
doctor = relationship("Doctors", back_populates="form_links")
|
||||
|
||||
|
||||
class PaymentMethod(Base):
|
||||
__tablename__ = "payment_methods"
|
||||
id = Column(Integer, primary_key=True)
|
||||
doctor_id = Column(UUID(as_uuid=True), ForeignKey("doctors.id", ondelete="CASCADE"), nullable=False)
|
||||
method = Column(String, nullable=False)
|
||||
details = Column(String, nullable=True)
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
created_at = Column(DateTime, nullable=False)
|
||||
|
||||
doctor = relationship("Doctor", back_populates="payment_methods")
|
||||
7
src/db/session.py
Normal file
7
src/db/session.py
Normal file
@ -0,0 +1,7 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
|
||||
|
||||
from core.config import settings
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL, echo=False, future=True)
|
||||
|
||||
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
||||
Loading…
x
Reference in New Issue
Block a user