|
1 | | -from datetime import datetime |
| 1 | +import datetime |
2 | 2 |
|
3 | 3 | from sqlalchemy import ForeignKey, String, UniqueConstraint, func |
| 4 | +from sqlalchemy.orm import Mapped, mapped_column |
| 5 | +from datetime import datetime |
4 | 6 | from sqlalchemy.orm import Mapped, mapped_column, relationship |
5 | 7 |
|
6 | 8 | from src.lib.database import Base |
7 | 9 |
|
8 | 10 |
|
9 | 11 | class Tag(Base): |
10 | | - __tablename__ = "tags" |
| 12 | + __tablename__ = "tag" |
| 13 | + __table_args__ = ( |
| 14 | + UniqueConstraint("user_id", "name", name="uq_tag_user_name"), |
| 15 | + ) |
11 | 16 |
|
12 | 17 | id: Mapped[int] = mapped_column(primary_key=True) |
13 | | - user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE")) |
| 18 | + user_id: Mapped[int] = mapped_column(ForeignKey("user_auth.id", ondelete="CASCADE")) |
14 | 19 | name: Mapped[str] = mapped_column(String(100)) |
| 20 | + color: Mapped[str] = mapped_column(String(7), server_default="'#6366f1'") |
| 21 | + created_at: Mapped[datetime.datetime] = mapped_column(server_default=func.now()) |
| 22 | + updated_at: Mapped[datetime.datetime] = mapped_column( |
| 23 | + server_default=func.now(), |
| 24 | + onupdate=func.now(), |
| 25 | + ) |
| 26 | + __tablename__ = "tags" |
| 27 | + user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE")) |
15 | 28 | created_at: Mapped[datetime] = mapped_column(server_default=func.now()) |
16 | 29 | updated_at: Mapped[datetime] = mapped_column(server_default=func.now(), onupdate=func.now()) |
17 | | - |
18 | 30 | contacts: Mapped[list["Contact"]] = relationship( # noqa: F821 |
19 | 31 | secondary="contact_tags", back_populates="tags" |
20 | | - ) |
21 | | - |
22 | 32 | __table_args__ = (UniqueConstraint("user_id", "name", name="uq_tag_user_name"),) |
0 commit comments