Commit 44c04b53 authored by root's avatar root

Fix: Now fully support mysql with long ids

parent 9f79a384
......@@ -65,7 +65,7 @@ class Bot(ABC):
def stop(self, db=None):
self.get_updater().stop()
self.get_updater().is_idle = False;
self.get_updater().is_idle = False
try:
db._session.close_all_sessions()
except Exception:
......@@ -130,4 +130,4 @@ class Bot(ABC):
update.reply_photo(photo=file)
except Exception:
logging.error("Cannot send error-meme!")
update.message.reply_text("Ups, something went wrong!\n'" + str(context.error)[:10] + "'")
\ No newline at end of file
update.message.reply_text("Ups, something went wrong!\n'" + str(context.error)[:15] + "'")
\ No newline at end of file
import logging
import logging
from DB.base import Base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session, Session
from sqlalchemy_utils.functions import database_exists, create_database
class Database:
......@@ -9,13 +10,15 @@ class Database:
_session = None
def __init__(self, connection_str):
if not database_exists(connection_str):
create_database(connection_str)
self._engine = create_engine(
connection_str,
encoding="latin1",
echo=True)
self._session = scoped_session(sessionmaker(bind=self._engine))
Base.metadata.create_all(self._engine)
def get_session(self):
return self._session()
......
Logs get generated here!
from DB.base import Base
from Model.chat import Chat
from Model.user import User
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy import Column, Integer, BigInteger, ForeignKey
from sqlalchemy.orm import relationship
class User_Chat(Base):
......@@ -9,8 +9,8 @@ class User_Chat(Base):
# Table
__tablename__ = "user_chat_assocation"
# Columns
user_id = Column(Integer, ForeignKey("user.id"), primary_key=True)
chat_id = Column(Integer, ForeignKey("chat.id"), primary_key=True)
user_id = Column(BigInteger, ForeignKey("user.id"), primary_key=True)
chat_id = Column(BigInteger, ForeignKey("chat.id"), primary_key=True)
# Relations
user = relationship("User", back_populates="chats")
chat = relationship("Chat", back_populates="users")
\ No newline at end of file
......@@ -2,7 +2,7 @@
from DB.base import Base
from Model.user import User
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class Chat(Base):
......@@ -10,7 +10,7 @@ class Chat(Base):
# Table
__tablename__ = "chat"
# Columns
id = Column(Integer, primary_key=True, autoincrement=False)
id = Column(BigInteger, primary_key=True, autoincrement=False)
username = Column(String(100))
ctype = Column(String(50))
title = Column(String(100))
......
......@@ -2,7 +2,7 @@ import datetime
from DB.base import Base
from Model.chat import Chat
from Model.user import User
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class Message(Base):
......@@ -10,9 +10,9 @@ class Message(Base):
# Table
__tablename__ = "message"
# Columns
id = Column(Integer, primary_key=True, autoincrement=False)
user_id = Column(Integer, ForeignKey("user.id"))
chat_id = Column(Integer, ForeignKey("chat.id"))
id = Column(BigInteger, primary_key=True, autoincrement=False)
user_id = Column(BigInteger, ForeignKey("user.id"))
chat_id = Column(BigInteger, ForeignKey("chat.id"))
text = Column(String(1024))
date = Column(String(50))
......
from DB.base import Base
from Model.user import User
from Model.poll_option import PollOption
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class Poll(Base):
......@@ -9,8 +9,8 @@ class Poll(Base):
# Table
__tablename__ = "poll"
# Columns
id = Column(Integer, primary_key=True, autoincrement=False)
user_id = Column(Integer, ForeignKey("user.id"))
id = Column(BigInteger, primary_key=True, autoincrement=False)
user_id = Column(BigInteger, ForeignKey("user.id"))
ptype = Column(String(50))
question = Column(String(512))
is_closed = Column(Boolean)
......
from DB.base import Base
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, String, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class PollOption(Base):
......@@ -7,8 +7,8 @@ class PollOption(Base):
# Table
__tablename__ = "polloption"
# Columns
id = Column(Integer, primary_key=True, autoincrement=True)
poll_id = Column(Integer, ForeignKey("poll.id"))
id = Column(BigInteger, primary_key=True, autoincrement=True)
poll_id = Column(BigInteger, ForeignKey("poll.id"))
text = Column(String(512))
voter_count = Column(Integer)
# Relations
......
from DB.base import Base
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, String, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class User(Base):
......@@ -7,7 +7,7 @@ class User(Base):
# Table
__tablename__ = "user"
# Columns
id = Column(Integer, primary_key=True, autoincrement=False)
id = Column(BigInteger, primary_key=True, autoincrement=False)
username = Column(String(100))
name = Column(String(100))
first_name = Column(String(100))
......
......@@ -2,7 +2,7 @@ from DB.base import Base
from Model.user import User
from Model.poll import Poll
from Model.poll_option import PollOption
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
from sqlalchemy import Column, Integer, String, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
class Vote(Base):
......@@ -10,10 +10,10 @@ class Vote(Base):
# Table
__tablename__ = "vote"
# Columns
id = Column(Integer, primary_key=True, autoincrement=False)
option_id = Column(Integer, ForeignKey("polloption.id"))
user_id = Column(Integer, ForeignKey("user.id"))
poll_id = Column(Integer, ForeignKey("poll.id"))
id = Column(BigInteger, primary_key=True, autoincrement=False)
option_id = Column(BigInteger, ForeignKey("polloption.id"))
user_id = Column(BigInteger, ForeignKey("user.id"))
poll_id = Column(BigInteger, ForeignKey("poll.id"))
is_right_option = Column(Boolean)
@staticmethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment