forked from mtusi2026/mtusi2026lab4
chore: carry lab 3 over
- carry the lab 3 solution over from mtusi2026lab3-safronov (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests, bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts, Dockerfile, compose, pyproject and uv lock - merge Makefile, .gitignore and .dockerignore (the lab 3 versions only add lines to the skeleton, which is the same in lab 4) and .env.example (lab 4 skeleton names listed in the header) - rename the compose project to mtusi-lab4 and the image to :lab4 so the stand does not reuse the lab 3 containers and volumes - update AGENTS.md for lab 4: current lab, origin commit, contract and test files of the new skeleton Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
from uuid import UUID
|
||||
|
||||
from sqlalchemy import CheckConstraint, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from src.infra.db.models.base import Base
|
||||
from src.utils.constants import (
|
||||
DISPLAY_NAME_MAX_LENGTH,
|
||||
DISPLAY_NAME_MIN_LENGTH,
|
||||
PASSWORD_HASH_PREFIX,
|
||||
USERNAME_PATTERN,
|
||||
)
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("username"),
|
||||
# CHECK дублируют контракт: первым отвечает API (400)
|
||||
CheckConstraint(
|
||||
f"username ~ '{USERNAME_PATTERN}'",
|
||||
name="username_format",
|
||||
),
|
||||
CheckConstraint(
|
||||
"char_length(display_name) BETWEEN "
|
||||
f"{DISPLAY_NAME_MIN_LENGTH} AND {DISPLAY_NAME_MAX_LENGTH}",
|
||||
name="display_name_length",
|
||||
),
|
||||
# защита в глубину: открытый пароль или быстрый хэш не запишется
|
||||
CheckConstraint(
|
||||
f"password_hash LIKE '{PASSWORD_HASH_PREFIX}%'",
|
||||
name="password_hash_argon2id",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[UUID] = mapped_column(primary_key=True)
|
||||
username: Mapped[str] = mapped_column(Text)
|
||||
display_name: Mapped[str] = mapped_column(Text)
|
||||
password_hash: Mapped[str] = mapped_column(Text)
|
||||
Reference in New Issue
Block a user