36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import os
|
|
from sqlalchemy import create_engine, Column, Integer, String
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
DATABASE_URL = os.environ.get("DATABASE_URL")
|
|
|
|
engine = create_engine(DATABASE_URL)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
twitch_id = Column(String, unique=True, index=True)
|
|
twitch_username = Column(String)
|
|
# We will store encrypted tokens
|
|
twitch_access_token = Column(String)
|
|
twitch_refresh_token = Column(String)
|
|
|
|
youtube_id = Column(String, unique=True, index=True, nullable=True)
|
|
youtube_username = Column(String, nullable=True)
|
|
youtube_access_token = Column(String, nullable=True)
|
|
youtube_refresh_token = Column(String, nullable=True)
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
def create_tables():
|
|
Base.metadata.create_all(bind=engine)
|