- models.py: add UniqueConstraint(user_id, date) to flock_history so duplicate flock entries for the same day are rejected at the DB level - main.py: v2.3 migration applies the new unique constraint to existing installs at startup - login.html: update register form minlength and placeholder from 6 to 10 characters to match backend; add specific 429 error message so rate- limited users see "Too many attempts — please wait a minute" instead of a generic failure - auth.js: update settings modal password input minlength from 6 to 10 - summary.js: fix CSV export truncation — pass limit=10000 so users with more than 500 days of data get a complete export; read chart border color from --green CSS variable instead of hardcoded hex - All HTML files: bump JS version params to ?v=4 so browsers discard cached copies of files changed across recent sessions (api.js, auth.js, dashboard.js, history.js, log.js, flock.js, budget.js, summary.js, admin.js) - .env.example: add password strength guidance for MySQL and admin vars Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
3.8 KiB
Python
69 lines
3.8 KiB
Python
from datetime import date, datetime
|
|
from sqlalchemy import Boolean, Integer, Date, DateTime, Text, Numeric, String, ForeignKey, UniqueConstraint, Index, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
from database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
username: Mapped[str] = mapped_column(String(64), unique=True, nullable=False, index=True)
|
|
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
is_admin: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
is_disabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
timezone: Mapped[str] = mapped_column(String(64), nullable=False, default='UTC')
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
|
|
class EggCollection(Base):
|
|
__tablename__ = "egg_collections"
|
|
__table_args__ = (UniqueConstraint("user_id", "date", name="uq_user_date"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
date: Mapped[date] = mapped_column(Date, nullable=False, index=True)
|
|
eggs: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
|
|
class FlockHistory(Base):
|
|
__tablename__ = "flock_history"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "date", name="uq_flock_user_date"),
|
|
Index("ix_flock_history_user_date", "user_id", "date"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
date: Mapped[date] = mapped_column(Date, nullable=False, index=True)
|
|
chicken_count: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
|
|
class FeedPurchase(Base):
|
|
__tablename__ = "feed_purchases"
|
|
__table_args__ = (Index("ix_feed_purchases_user_date", "user_id", "date"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
date: Mapped[date] = mapped_column(Date, nullable=False, index=True)
|
|
bags: Mapped[float] = mapped_column(Numeric(5, 2), nullable=False)
|
|
price_per_bag: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False)
|
|
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
|
|
|
|
class OtherPurchase(Base):
|
|
__tablename__ = "other_purchases"
|
|
__table_args__ = (Index("ix_other_purchases_user_date", "user_id", "date"),)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
date: Mapped[date] = mapped_column(Date, nullable=False, index=True)
|
|
total: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False)
|
|
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|