added more pomidoro

This commit is contained in:
2026-06-09 11:54:32 +03:00
parent 244935e4ac
commit c8599b3d13
20 changed files with 817 additions and 91 deletions
+2
View File
@@ -27,8 +27,10 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def init_db() -> None:
from app.db import models # noqa: F401
from app.db.migrate import run_migrations
Base.metadata.create_all(bind=engine)
run_migrations()
def get_db() -> Generator[Session, None, None]:
+32
View File
@@ -0,0 +1,32 @@
from sqlalchemy import inspect, text
from app.db.base import engine
def run_migrations() -> None:
inspector = inspect(engine)
if "pomodoro_sessions" in inspector.get_table_names():
columns = {col["name"] for col in inspector.get_columns("pomodoro_sessions")}
with engine.begin() as conn:
if "phase" not in columns:
conn.execute(
text("ALTER TABLE pomodoro_sessions ADD COLUMN phase VARCHAR(32) DEFAULT 'work'")
)
if "completion_notified" not in columns:
conn.execute(
text(
"ALTER TABLE pomodoro_sessions "
"ADD COLUMN completion_notified BOOLEAN DEFAULT 0"
)
)
if "pomodoro_cycles" not in inspector.get_table_names():
return
columns = {col["name"] for col in inspector.get_columns("pomodoro_cycles")}
with engine.begin() as conn:
if "chat_notify_seq" not in columns:
conn.execute(
text("ALTER TABLE pomodoro_cycles ADD COLUMN chat_notify_seq INTEGER DEFAULT 0")
)
+19
View File
@@ -35,15 +35,34 @@ class Message(Base):
session: Mapped["ChatSession"] = relationship(back_populates="messages")
class PomodoroCycle(Base):
__tablename__ = "pomodoro_cycles"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
work_duration_min: Mapped[int] = mapped_column(Integer, default=25)
short_break_min: Mapped[int] = mapped_column(Integer, default=5)
long_break_min: Mapped[int] = mapped_column(Integer, default=15)
sessions_until_long_break: Mapped[int] = mapped_column(Integer, default=4)
completed_work_sessions: Mapped[int] = mapped_column(Integer, default=0)
task_note: Mapped[str] = mapped_column(Text, default="")
auto_advance: Mapped[bool] = mapped_column(Boolean, default=True)
chat_notify_seq: Mapped[int] = mapped_column(Integer, default=0)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
)
class PomodoroSession(Base):
__tablename__ = "pomodoro_sessions"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
status: Mapped[str] = mapped_column(String(32), default="idle")
phase: Mapped[str] = mapped_column(String(32), default="work")
duration_min: Mapped[int] = mapped_column(Integer, default=25)
task_note: Mapped[str] = mapped_column(Text, default="")
result: Mapped[str | None] = mapped_column(Text, nullable=True)
completed: Mapped[bool] = mapped_column(Boolean, default=False)
completion_notified: Mapped[bool] = mapped_column(Boolean, default=False)
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
paused_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
elapsed_seconds: Mapped[int] = mapped_column(Integer, default=0)