Beispiel #1
0
class User(db.Model):
    __tablename__ = "users"

    user_id = db.Column(db.Integer, primary_key=True)
    external_id = db.Column(db.String, nullable=False, unique=True)
    name = db.Column(db.String, nullable=False)
    admin = db.Column(db.Boolean, nullable=False, default=False)

    def __repr__(self):
        return f"<User: {self.name} ({self.email})>"
Beispiel #2
0
class Track(db.Model):
    __tablename__ = "tracks"

    track_id = db.Column(db.String, primary_key=True, autoincrement=False)
    name = db.Column(db.String, nullable=False)
    sanitized_name = db.Column(db.String, nullable=True)
    album_id = db.Column(
        db.String, db.ForeignKey("albums.album_id"), nullable=False)
    duration_ms = db.Column(db.Integer, nullable=False)
    disc_no = db.Column(db.Integer, nullable=False)
    explicit = db.Column(db.Boolean, nullable=False)
    track_number = db.Column(db.Integer, nullable=True)

    artists = db.relationship(Artist, secondary=association_table,
                              backref="tracks", lazy="joined")

    performance_id = db.Column(
        db.Integer, db.ForeignKey(
            "performances.performance_id"), nullable=True)

    def __repr__(self):
        return f"<Track: {self.name}>"

    def __eq__(self, other):
        if not isinstance(other, Track):
            return False

        return self.track_id == other.track_id
Beispiel #3
0
class Album(db.Model):
    __tablename__ = "albums"
    album_id = db.Column(db.String(), primary_key=True, autoincrement=False)
    album_type = db.Column(db.String(), nullable=False)
    image_url = db.Column(db.String(), nullable=True)
    name = db.Column(db.String(), nullable=False)

    release_date = db.Column(db.Date, nullable=False)
    tracks = db.relationship(Track, backref="album", lazy="raise")
    performances = db.relationship(Performance, backref="album", lazy="raise")

    def __repr__(self):
        return f"<Album: {self.name}>"

    def __eq__(self, other):
        if not isinstance(other, Album):
            return False

        return self.album_id == other.album_id
class Performance(db.Model):
    __tablename__ = "performances"

    performance_id = db.Column(db.Integer, primary_key=True)
    tracks = db.relationship(Track, backref="performance", lazy="joined")
    work_id = db.Column(db.Integer,
                        db.ForeignKey("works.work_id"),
                        nullable=False)
    album_id = db.Column(db.String,
                         db.ForeignKey("albums.album_id"),
                         nullable=False)

    def __eq__(self, other):
        if not isinstance(other, Performance):
            return False

        return self.work == other.work and \
            self.album_id == other.album_id

    def __repr__(self):
        return f"<Performance: Work - {self.work_id}, Album - {self.album_id}>"
Beispiel #5
0
class Artist(db.Model):
    __tablename__ = "artists"
    artist_id = db.Column(db.String(), primary_key=True, autoincrement=False)
    image_url = db.Column(db.String(), nullable=True)
    name = db.Column(db.String(), nullable=False)

    composer_id = db.Column(db.Integer,
                            db.ForeignKey("composers.composer_id"),
                            nullable=True)

    def __repr__(self) -> str:
        return f"<Artist: {self.name}>"

    def __eq__(self, other) -> bool:
        if not isinstance(other, Artist):
            return False

        return self.artist_id == other.artist_id

    def __hash__(self):
        return hash(self.artist_id)
Beispiel #6
0
class Composer(db.Model):
    __tablename__ = "composers"

    composer_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False, info={"label": "Name"})
    birth_year = db.Column(db.Integer,
                           nullable=False,
                           info={"label": "Year of Birth"})

    death_year = db.Column(db.Integer,
                           nullable=True,
                           info={"label": "Year of Death"})

    country = db.Column(db.String(),
                        nullable=False,
                        info={"label": "Country of Origin"})

    biography = db.Column(db.String(),
                          nullable=True,
                          info={"label": "Biography"})

    works = db.relationship(Work, backref="composer")

    artist = db.relationship(Artist, backref="composer", uselist=False)

    death_after = db.CheckConstraint("birth_year < death_year",
                                     name="death_after")

    def __repr__(self):
        return f"<Composer: {self.name}>"

    def __str__(self):
        return self.name
Beispiel #7
0
class Work(db.Model):
    __tablename__ = "works"

    work_id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(), nullable=False)
    composer_id = db.Column(db.Integer,
                            ForeignKey("composers.composer_id"
                                       ""),
                            nullable=False)

    catalog_no = db.Column(db.String(), nullable=True)
    opus_no = db.Column(db.String(), nullable=True)
    date_written = db.Column(db.Date, nullable=True)
    more_info = db.Column(db.String(), nullable=True)
    performances = db.relationship(Performance, backref="work")

    def __init__(self):
        self.album = None
        self.composer = None

    def __repr__(self):
        return f"<Work: {self.composer.name}: {self.name}>"

    def __eq__(self, other):

        if not isinstance(other, Work):
            return False
        else:

            return self.composer_id == other.composer_id and \
                   self.opus_no == other.opus_no and \
                   self.catalog_no == other.catalog_no

    def __hash__(self):

        return hash((self.composer_id, self.opus_no, self.catalog_no))
Beispiel #8
0
from spotify_opus import db
from spotify_opus.models.Artist import Artist

association_table = db.Table(
    'tracks_artists',
    db.Column('track_id', db.String, db.ForeignKey('tracks.track_id')),
    db.Column('artist_id', db.String, db.ForeignKey('artists.artist_id'))
)


class Track(db.Model):
    __tablename__ = "tracks"

    track_id = db.Column(db.String, primary_key=True, autoincrement=False)
    name = db.Column(db.String, nullable=False)
    sanitized_name = db.Column(db.String, nullable=True)
    album_id = db.Column(
        db.String, db.ForeignKey("albums.album_id"), nullable=False)
    duration_ms = db.Column(db.Integer, nullable=False)
    disc_no = db.Column(db.Integer, nullable=False)
    explicit = db.Column(db.Boolean, nullable=False)
    track_number = db.Column(db.Integer, nullable=True)

    artists = db.relationship(Artist, secondary=association_table,
                              backref="tracks", lazy="joined")

    performance_id = db.Column(
        db.Integer, db.ForeignKey(
            "performances.performance_id"), nullable=True)

    def __repr__(self):