Implement Phase 1: User Authentication & Database (Twitch OAuth, Login Page)
This commit is contained in:
37
database.py
Normal file
37
database.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from sqlalchemy import create_engine, Column, Integer, String
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
DATABASE_URL = "sqlite:///./multichat.db"
|
||||
|
||||
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
||||
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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_tables()
|
||||
Reference in New Issue
Block a user