22 lines
901 B
Python
22 lines
901 B
Python
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.sql import func
|
|
from app.db.base import Base
|
|
|
|
class List(Base):
|
|
__tablename__ = "lists"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
name = Column(String, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
class ListMember(Base):
|
|
__tablename__ = "list_members"
|
|
__table_args__ = (
|
|
UniqueConstraint('list_id', 'contact_id', name='uq_list_contact'),
|
|
)
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
list_id = Column(Integer, ForeignKey("lists.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
contact_id = Column(Integer, ForeignKey("contacts.id", ondelete="CASCADE"), nullable=False, index=True)
|