Initial commit: habit tracker PWA with Google OAuth, push notifications
FastAPI + SQLAlchemy/Alembic + MariaDB backend with Jinja2/htmx/Alpine server-rendered frontend. Multi-user via Google OAuth, daily habit tracking, monthly/weekly history views, Web Push reminders via APScheduler, and PWA support (manifest, service worker, offline caching). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""initial schema: habit, habit_log, push_subscription, habit_notification_log
|
||||
|
||||
Revision ID: 0001_initial
|
||||
Revises:
|
||||
Create Date: 2026-07-09
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0001_initial"
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"habit",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("name", sa.String(length=200), nullable=False),
|
||||
sa.Column("habit_type", sa.String(length=20), nullable=False),
|
||||
sa.Column("status", sa.String(length=20), nullable=False, server_default="active"),
|
||||
sa.Column("weekdays_mask", sa.SmallInteger(), nullable=False, server_default="127"),
|
||||
sa.Column("reminder_time", sa.Time(), nullable=True),
|
||||
sa.Column("sort_order", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.Column("completed_at", sa.DateTime(), nullable=True),
|
||||
sa.CheckConstraint("habit_type in ('build','quit')", name="ck_habit_habit_type"),
|
||||
sa.CheckConstraint("status in ('active','completed')", name="ck_habit_status"),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"habit_log",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("habit_id", sa.Integer(), sa.ForeignKey("habit.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("log_date", sa.Date(), nullable=False),
|
||||
sa.Column("checked_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("habit_id", "log_date", name="uq_habit_log_habit_date"),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"push_subscription",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("endpoint", sa.String(length=512), nullable=False, unique=True),
|
||||
sa.Column("p256dh_key", sa.String(length=255), nullable=False),
|
||||
sa.Column("auth_key", sa.String(length=255), nullable=False),
|
||||
sa.Column("user_agent", sa.String(length=255), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"habit_notification_log",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("habit_id", sa.Integer(), sa.ForeignKey("habit.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("notify_date", sa.Date(), nullable=False),
|
||||
sa.Column("sent_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("habit_id", "notify_date", name="uq_notification_habit_date"),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("habit_notification_log")
|
||||
op.drop_table("push_subscription")
|
||||
op.drop_table("habit_log")
|
||||
op.drop_table("habit")
|
||||
@@ -0,0 +1,24 @@
|
||||
"""add condition_text to habit
|
||||
|
||||
Revision ID: 0002_add_condition_text
|
||||
Revises: 0001_initial
|
||||
Create Date: 2026-07-14
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0002_add_condition_text"
|
||||
down_revision: Union[str, None] = "0001_initial"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("habit", sa.Column("condition_text", sa.String(length=300), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("habit", "condition_text")
|
||||
@@ -0,0 +1,34 @@
|
||||
"""add user table
|
||||
|
||||
Revision ID: 0003_add_user_table
|
||||
Revises: 0002_add_condition_text
|
||||
Create Date: 2026-07-15
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0003_add_user_table"
|
||||
down_revision: Union[str, None] = "0002_add_condition_text"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"user",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("google_sub", sa.String(length=255), nullable=False, unique=True),
|
||||
sa.Column("email", sa.String(length=255), nullable=False, unique=True),
|
||||
sa.Column("name", sa.String(length=255), nullable=True),
|
||||
sa.Column("picture_url", sa.String(length=512), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("user")
|
||||
@@ -0,0 +1,41 @@
|
||||
"""add user_id to habit and push_subscription
|
||||
|
||||
Revision ID: 0004_add_user_id_columns
|
||||
Revises: 0003_add_user_table
|
||||
Create Date: 2026-07-15
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0004_add_user_id_columns"
|
||||
down_revision: Union[str, None] = "0003_add_user_table"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("habit", sa.Column("user_id", sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(
|
||||
"fk_habit_user_id", "habit", "user", ["user_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
|
||||
op.add_column("push_subscription", sa.Column("user_id", sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(
|
||||
"fk_push_subscription_user_id",
|
||||
"push_subscription",
|
||||
"user",
|
||||
["user_id"],
|
||||
["id"],
|
||||
ondelete="CASCADE",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint("fk_push_subscription_user_id", "push_subscription", type_="foreignkey")
|
||||
op.drop_column("push_subscription", "user_id")
|
||||
|
||||
op.drop_constraint("fk_habit_user_id", "habit", type_="foreignkey")
|
||||
op.drop_column("habit", "user_id")
|
||||
@@ -0,0 +1,34 @@
|
||||
"""add summary_notification_log table
|
||||
|
||||
Revision ID: 0005_add_summary_notification_log
|
||||
Revises: 0004_add_user_id_columns
|
||||
Create Date: 2026-07-16
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0005_add_summary_notif_log"
|
||||
down_revision: Union[str, None] = "0004_add_user_id_columns"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"summary_notification_log",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("user_id", sa.Integer(), sa.ForeignKey("user.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("period_type", sa.String(length=20), nullable=False),
|
||||
sa.Column("period_start", sa.Date(), nullable=False),
|
||||
sa.Column("sent_at", sa.DateTime(), nullable=False, server_default=sa.func.now()),
|
||||
sa.UniqueConstraint("user_id", "period_type", "period_start", name="uq_summary_user_period"),
|
||||
mysql_engine="InnoDB",
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("summary_notification_log")
|
||||
Reference in New Issue
Block a user