2023-08-02 00:03:47 +03:00
|
|
|
from datetime import datetime
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "users"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
user_id = Column(String, primary_key=True)
|
|
|
|
email = Column(String)
|
|
|
|
date = Column(DateTime)
|
2023-08-21 15:05:13 +03:00
|
|
|
daily_requests_count = Column(Integer)
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Brain(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "brains"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
brain_id = Column(Integer, primary_key=True)
|
|
|
|
name = Column(String)
|
2023-08-21 15:05:13 +03:00
|
|
|
users = relationship("BrainUser", back_populates="brain")
|
|
|
|
vectors = relationship("BrainVector", back_populates="brain")
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
class BrainUser(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "brains_users"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
2023-08-21 15:05:13 +03:00
|
|
|
user_id = Column(Integer, ForeignKey("users.user_id"))
|
|
|
|
brain_id = Column(Integer, ForeignKey("brains.brain_id"))
|
2023-08-02 00:03:47 +03:00
|
|
|
rights = Column(String)
|
|
|
|
|
2023-08-21 15:05:13 +03:00
|
|
|
user = relationship("User")
|
|
|
|
brain = relationship("Brain", back_populates="users")
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
class BrainVector(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "brains_vectors"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
vector_id = Column(String, primary_key=True, default=lambda: str(uuid4()))
|
2023-08-21 15:05:13 +03:00
|
|
|
brain_id = Column(Integer, ForeignKey("brains.brain_id"))
|
2023-08-02 00:03:47 +03:00
|
|
|
file_sha1 = Column(String)
|
|
|
|
|
2023-08-21 15:05:13 +03:00
|
|
|
brain = relationship("Brain", back_populates="vectors")
|
|
|
|
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
class BrainSubscriptionInvitation(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "brain_subscription_invitations"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True) # Assuming an integer primary key named 'id'
|
2023-08-21 15:05:13 +03:00
|
|
|
brain_id = Column(String, ForeignKey("brains.brain_id"))
|
|
|
|
email = Column(String, ForeignKey("users.email"))
|
2023-08-02 00:03:47 +03:00
|
|
|
rights = Column(String)
|
|
|
|
|
2023-08-21 15:05:13 +03:00
|
|
|
brain = relationship("Brain")
|
|
|
|
user = relationship("User", foreign_keys=[email])
|
|
|
|
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
class ApiKey(Base):
|
2023-08-21 15:05:13 +03:00
|
|
|
__tablename__ = "api_keys"
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
key_id = Column(String, primary_key=True, default=lambda: str(uuid4()))
|
2023-08-21 15:05:13 +03:00
|
|
|
user_id = Column(Integer, ForeignKey("users.user_id"))
|
2023-08-02 00:03:47 +03:00
|
|
|
api_key = Column(String, unique=True)
|
|
|
|
creation_time = Column(DateTime, default=datetime.utcnow)
|
|
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
deleted_time = Column(DateTime, nullable=True)
|
|
|
|
|
2023-08-21 15:05:13 +03:00
|
|
|
user = relationship("User")
|