2020-01-27 23:28:14 -05:00
|
|
|
from sqlalchemy import Column, DateTime, BigInteger, String, Integer, Numeric, ForeignKey, func
|
2018-01-28 18:29:58 -05:00
|
|
|
from sqlalchemy.orm import relationship, backref
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
2018-01-30 18:23:53 -05:00
|
|
|
import os
|
|
|
|
|
2018-10-16 11:54:47 -04:00
|
|
|
# Localhost url: postgresql://localhost/postgres
|
2018-01-30 18:23:53 -05:00
|
|
|
postgres_url = os.environ["TELEGRAM_BOT_POSTGRES_URL"]
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
|
|
|
|
'''
|
|
|
|
This model has been referenced from: https://www.pythoncentral.io/sqlalchemy-orm-examples/
|
2018-01-29 00:29:50 -05:00
|
|
|
'''
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
Base = declarative_base()
|
2018-01-29 00:29:50 -05:00
|
|
|
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
class User(Base):
|
2018-01-30 18:23:53 -05:00
|
|
|
__tablename__ = 'telegram_users'
|
2018-01-28 18:29:58 -05:00
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
first_name = Column(String)
|
|
|
|
last_name = Column(String)
|
|
|
|
username = Column(String)
|
2018-01-29 00:29:50 -05:00
|
|
|
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
class Message(Base):
|
2018-01-30 18:23:53 -05:00
|
|
|
__tablename__ = 'telegram_messages'
|
2018-01-28 18:29:58 -05:00
|
|
|
id = Column(Integer, primary_key=True)
|
2018-01-30 18:23:53 -05:00
|
|
|
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
|
2018-01-28 18:29:58 -05:00
|
|
|
message = Column(String)
|
2020-01-27 21:24:25 -05:00
|
|
|
language_code = Column(String)
|
|
|
|
english_message = Column(String)
|
2020-01-24 20:51:34 -05:00
|
|
|
chat_id = Column(BigInteger)
|
2020-01-27 23:08:00 -05:00
|
|
|
polarity = Column(Numeric)
|
|
|
|
subjectivity = Column(Numeric)
|
2018-02-09 20:13:09 -05:00
|
|
|
time = Column(DateTime, default=func.now())
|
|
|
|
|
|
|
|
class MessageHide(Base):
|
|
|
|
__tablename__ = 'telegram_message_hides'
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
|
|
|
|
message = Column(String)
|
|
|
|
time = Column(DateTime, default=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
class UserBan(Base):
|
|
|
|
__tablename__ = 'telegram_user_bans'
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
user_id = Column(Integer, ForeignKey('telegram_users.id'), nullable=False)
|
|
|
|
reason = Column(String)
|
2018-01-28 18:29:58 -05:00
|
|
|
time = Column(DateTime, default=func.now())
|
2018-01-29 00:29:50 -05:00
|
|
|
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
from sqlalchemy import create_engine
|
2018-01-29 00:29:50 -05:00
|
|
|
engine = create_engine(postgres_url)
|
|
|
|
|
2018-01-28 18:29:58 -05:00
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
session = sessionmaker()
|
|
|
|
session.configure(bind=engine)
|
|
|
|
Base.metadata.create_all(engine)
|
2018-02-09 20:13:09 -05:00
|
|
|
|
2018-01-30 18:44:44 -05:00
|
|
|
print ("Created database model")
|