class ArtistGenreAssociation(db.Model): """ Linking Artist to Genres """ __tablename__ = 'artist_genre' #: Artist Primary Key artist_id = db.Column(db.ForeignKey('artist.id'), primary_key=True, index=True) #: Genre Primary Key grenre_id = db.Column(db.ForeignKey('genre.id'), primary_key=True, index=True) # # Relations # artist = db.relationship('Artist', backref='genre_associations', lazy='joined') genre = db.relationship('Genre', backref='artist_associations', lazy='joined')
class ArtistAlbumAssociation(db.Model): """ Link table joining Album to Artist """ __tablename__ = 'artist_album' #: Artist Primary Key artist_id = db.Column(db.ForeignKey('artist.id'), primary_key=True, index=True) #: Album Primary Key album_id = db.Column(db.ForeignKey('album.id'), primary_key=True, index=True) # # Relations # artist = db.relationship('Artist', backref='album_associations', lazy='joined') album = db.relationship('Album', backref='artist_associations', lazy='joined')
class TrackArtistAssociation(db.Model): """ Linking Tracks to Artists """ __tablename__ = 'artist_track' __table_args__ = (UniqueConstraint('artist_id', 'track_id'), ) #: Artist Primary Key artist_id = db.Column(db.ForeignKey('artist.id'), primary_key=True, index=True) #: Track Primary Key track_id = db.Column(db.ForeignKey('track.id'), primary_key=True, index=True) # # Relations # artist = db.relationship('Artist', backref='track_associations', lazy='joined') track = db.relationship('Track', backref='artist_associations', lazy='joined')
class PlaylistHistory(db.Model): """ Holds the playlist history """ __tablename__ = 'playlist_history' #: Primary Key id = db.Column(UUID, primary_key=True, default=lambda: unicode(uuid.uuid4())) #: Track ID track_id = db.Column(db.ForeignKey('track.id'), nullable=False, index=True) #: User ID user_id = db.Column(db.ForeignKey('user.id'), nullable=False, index=True) # # Relations # track = db.relation('Track', lazy='joined') user = db.relation('User', lazy='joined')
class Track(db.Model): """ Holds spotify track data """ __tablename__ = 'track' #: Primary Key id = db.Column(UUID, primary_key=True, default=lambda: unicode(uuid.uuid4())) #: Spotify ID - spotify:track:67WTwafOMgegV6ABnBQxcE spotify_uri = db.Column(db.Unicode(129), unique=True, nullable=False, index=True) #: Album ID album_id = db.Column(db.ForeignKey('album.id'), nullable=False, index=True) #: Track Name name = db.Column(db.Unicode(128)) #: Duration in miliseconds duration = db.Column(db.Integer) #: Total number of times the track has been played play_count = db.Column(db.Integer, default=0, server_default='0', nullable=False, index=True) #: Audio analysis from Echonest audio_summary = db.Column(JSON) # # Relations # album = db.relation('Album', backref='tracks', lazy='joined') artists = association_proxy( 'artist_associations', 'artist', creator=lambda artist: TrackArtistAssociation(artist=artist))