new bot structure
This commit is contained in:
12
app/infrastructure/database/database.py
Normal file
12
app/infrastructure/database/database.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from config import DATABASE_URL
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
engine = create_async_engine(DATABASE_URL, echo=True)
|
||||
Base = declarative_base()
|
||||
async_session = sessionmaker(bind=engine, expire_on_commit=False, class_=AsyncSession)
|
||||
|
||||
|
||||
async def get_session() -> AsyncSession:
|
||||
async with async_session() as session:
|
||||
yield session
|
||||
39
app/infrastructure/database/models.py
Normal file
39
app/infrastructure/database/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import datetime as dt
|
||||
|
||||
from sqlalchemy import (
|
||||
BigInteger,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.db.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
fullname: Mapped[str] = mapped_column()
|
||||
tg_id: Mapped[int] = mapped_column(BigInteger)
|
||||
phone: Mapped[str] = mapped_column(nullable=True)
|
||||
|
||||
|
||||
class Event(Base):
|
||||
__tablename__ = "event"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
title: Mapped[str] = mapped_column()
|
||||
description: Mapped[str] = mapped_column(default="")
|
||||
start_date: Mapped[dt.date] = mapped_column(nullable=True)
|
||||
end_date: Mapped[dt.date] = mapped_column(nullable=True)
|
||||
|
||||
|
||||
class UserEvent(Base):
|
||||
__tablename__ = "user_event"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
user: Mapped[int] = mapped_column(ForeignKey("user.id"))
|
||||
event: Mapped[int] = mapped_column(ForeignKey("event.id"))
|
||||
date: Mapped[dt.date] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
status: Mapped[str] = mapped_column(default="not confirmed")
|
||||
Reference in New Issue
Block a user