forked from kodorvan/stcs
The database has been converted to SQLite
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
import logging.config
|
||||
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine, AsyncSession
|
||||
|
||||
from database.models import Base
|
||||
|
||||
import logging.config
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
|
||||
from sqlalchemy import event
|
||||
from config import DATABASE_URL
|
||||
|
||||
from logger_helper.logger_helper import LOGGING_CONFIG
|
||||
|
||||
logging.config.dictConfig(LOGGING_CONFIG)
|
||||
logger = logging.getLogger("database")
|
||||
|
||||
async_engine = create_async_engine(DATABASE_URL, echo=False)
|
||||
|
||||
async_session = async_sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False)
|
||||
async_engine = create_async_engine(
|
||||
DATABASE_URL,
|
||||
echo=False,
|
||||
connect_args={"check_same_thread": False}
|
||||
)
|
||||
|
||||
@event.listens_for(async_engine.sync_engine, "connect")
|
||||
def _enable_foreign_keys(dbapi_connection, connection_record):
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA foreign_keys=ON")
|
||||
cursor.close()
|
||||
|
||||
async_session = async_sessionmaker(
|
||||
async_engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False
|
||||
)
|
||||
|
||||
async def init_db():
|
||||
try:
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.asyncio import AsyncAttrs
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, BigInteger, Float, Boolean, UniqueConstraint
|
||||
from sqlalchemy import Column, ForeignKey, Integer, String, Float, Boolean, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
Base = declarative_base(cls=AsyncAttrs)
|
||||
@@ -11,7 +11,7 @@ class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
tg_id = Column(BigInteger, nullable=False, unique=True)
|
||||
tg_id = Column(Integer, nullable=False, unique=True)
|
||||
username = Column(String, nullable=False)
|
||||
|
||||
user_api = relationship("UserApi",
|
||||
@@ -175,4 +175,4 @@ class UserAutoTrading(Base):
|
||||
fee = Column(Float, nullable=True)
|
||||
total_fee = Column(Float, nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="user_auto_trading")
|
||||
user = relationship("User", back_populates="user_auto_trading")
|
||||
|
Reference in New Issue
Block a user