20 lines
847 B
Python
20 lines
847 B
Python
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Album(Base):
|
|
id = Column(String, primary_key=True, index=True)
|
|
title = Column(String, index=True, nullable=False)
|
|
artist_id = Column(String, ForeignKey("artist.id"), nullable=False)
|
|
release_year = Column(Integer, nullable=True)
|
|
cover_image = Column(String, nullable=True)
|
|
description = Column(Text, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
artist = relationship("Artist", back_populates="albums")
|
|
songs = relationship("Song", back_populates="album", cascade="all, delete-orphan") |