feat(db): Alembic migration for users table (async env, DATABASE_URL)
build-image / test (push) Successful in 10s
build-image / build (push) Successful in 24s

Adds alembic/ (async env.py driven by DATABASE_URL) and the 0001 users-table
migration matching the model. enabled now has a DB-level server_default of false
(secure default even for non-ORM inserts). Verified upgrade/downgrade on sqlite.
This commit is contained in:
2026-07-04 19:35:55 -04:00
parent f067f9639a
commit 8204675a66
6 changed files with 160 additions and 2 deletions
+5 -2
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
from datetime import datetime
from sqlalchemy import Boolean, DateTime, LargeBinary, String, func
from sqlalchemy import Boolean, DateTime, LargeBinary, String, false, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
@@ -31,7 +31,10 @@ class User(Base):
athlete_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
api_key_enc: Mapped[bytes | None] = mapped_column(LargeBinary, nullable=True)
enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
# Secure default: any row created outside the ORM still lands disabled.
enabled: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=False, server_default=false()
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()