fix(models): align Station unique constraint + extend tests

- Station.code: usa UniqueConstraint("code", name="uq_stations_code")
  esplicito in __table_args__ invece di unique=True sulla colonna,
  per allineamento con la migration 002 ed evitare drift Alembic.
- Aggiunge test test_duplicate_assignment_is_rejected per coprire
  il vincolo uq_station_recipe (regola business centrale del modello).
- Sposta import IntegrityError a module-level per consistenza.

Feedback da code-reviewer su Task 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 22:22:14 +02:00
parent 5959c9c92a
commit e36bbbb7d7
2 changed files with 21 additions and 2 deletions
+2 -1
View File
@@ -20,7 +20,7 @@ class Station(Base):
__tablename__ = "stations"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
code: Mapped[str] = mapped_column(String(100), unique=True, nullable=False, index=True)
code: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
location: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
notes: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
@@ -35,6 +35,7 @@ class Station(Base):
)
__table_args__ = (
UniqueConstraint("code", name="uq_stations_code"),
{"mysql_engine": "InnoDB", "mysql_charset": "utf8mb4"},
)