32 lines
971 B
Python
32 lines
971 B
Python
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, func
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.database import Base
|
|
|
|
|
|
class Collection(Base):
|
|
__tablename__ = "collections"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(120), nullable=False, unique=True)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
|
|
characters = relationship(
|
|
"Character",
|
|
back_populates="collection",
|
|
cascade="all, delete-orphan",
|
|
)
|
|
|
|
|
|
class Character(Base):
|
|
__tablename__ = "characters"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(255), nullable=False)
|
|
filename = Column(String(255), nullable=False)
|
|
s3_url = Column(String(1024), nullable=False)
|
|
collection_id = Column(
|
|
Integer, ForeignKey("collections.id", ondelete="CASCADE"), nullable=False
|
|
)
|
|
|
|
collection = relationship("Collection", back_populates="characters")
|