Files
microfish/backend/app/models/password_reset.py
Kunthawat Greethong e572bc910f fix: boolean server_default must be 'false' not '0' for Postgres
PostgreSQL rejects BOOLEAN DEFAULT 0 (DatatypeMismatch: column ... is of type
boolean but default expression is of type integer). Migration 0008
(platform_settings.active) crashed the alembic upgrade run by the entrypoint,
which in turn crash-looped the worker. Migration 0011 (password_reset_tokens.
used) had the same latent bug and would have failed next.

Change the Boolean server_default from text('0') to text('false') in both
migrations and both ORM models so the DDL is valid on both PostgreSQL
(production) and SQLite (local/tests).

Verified: full 0001->0011 chain runs on fresh SQLite; alembic check reports no
drift; backend suite 201 passed.
2026-08-31 22:21:53 +07:00

38 lines
1.3 KiB
Python

"""Durable, single-use password reset tokens."""
from __future__ import annotations
from datetime import datetime, timezone
from uuid import uuid4
from sqlalchemy import Boolean, DateTime, ForeignKey, String, func, text
from sqlalchemy.orm import Mapped, mapped_column
from ..db import Base
def _utc_now() -> datetime:
return datetime.now(timezone.utc)
class PasswordResetToken(Base):
"""One hash of a one-time reset token; plaintext is never stored."""
__tablename__ = "password_reset_tokens"
id: Mapped[str] = mapped_column(
String(64), primary_key=True, default=lambda: f"prt_{uuid4().hex}"
)
user_id: Mapped[str] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
)
token_hash: Mapped[str] = mapped_column(String(128), nullable=False)
auth_version: Mapped[int] = mapped_column(nullable=False, default=0, server_default=text("0"))
used: Mapped[bool] = mapped_column(
Boolean, nullable=False, default=False, server_default=text("false")
)
expires_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, default=_utc_now, server_default=func.now()
)