-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
89 lines (72 loc) · 2.7 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from sqlalchemy import Column, Integer, String, ForeignKey, Table
from sqlalchemy.orm import relation, relationship, backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.sqltypes import Float
Base = declarative_base()
# artist_album = Table(
# "artists_albums",
# Base.metadata,
# Column("artist_id", String, ForeignKey("artists.spotify_id")),
# Column("album_id", String, ForeignKey("albums.spotify_id"))
# )
# artist_genre = Table(
# "artists_genres",
# Base.metadata,
# Column("artist_id", String, ForeignKey("artists.spotify_id")),
# Column("genre", String, ForeignKey("genres.name"))
# )
class Album(Base):
__tablename__ = "albums"
spotify_id = Column(String, primary_key=True)
lead_artist_id = Column(String, ForeignKey("artists.spotify_id"))
name = Column(String)
popularity = Column(Integer)
cover_url = Column(String)
release_date = Column(String)
type = Column(String)
label = Column(String)
artists = relationship('Artist', back_populates="albums")
tracks = relationship('Track', back_populates="album")
class Artist(Base):
__tablename__ = "artists"
spotify_id = Column(String, primary_key=True)
name = Column(String)
popularity = Column(Integer)
image_url = Column(String)
albums = relationship("Album", back_populates="artists")
tracks = relationship("Track", back_populates="lead_artist")
# class Genre(Base):
# __tablename__ = "genres"
# name = Column(String, primary_key=True)
#artists = relationship(
# "Artist", secondary="artist_genre", back_populates="genres")
class Scrobble(Base):
__tablename__ = "scrobbles"
id = Column(Integer, primary_key=True)
timestamp = Column(String)
spotify_id = Column(String, ForeignKey("tracks.spotify_id"))
track_name = Column(String)
class Track(Base):
__tablename__ = "tracks"
spotify_id = Column(String, primary_key=True)
name = Column(String)
lead_artist_id = Column(String, ForeignKey("artists.spotify_id"))
album_id = Column(String, ForeignKey("albums.spotify_id"))
length_ms = Column(Integer)
explicit = Column(Integer)
popularity = Column(Integer)
track_number = Column(Integer)
acousticness = Column(Float)
danceability = Column(Float)
energy = Column(Float)
instrumentalness = Column(Float)
key = Column(Integer)
liveness = Column(Float)
mode = Column(Integer)
speechiness = Column(Float)
tempo = Column(Float)
valence = Column(Float)
time_signature = Column(Float)
album = relationship("Album", back_populates="tracks")
lead_artist = relationship("Artist", back_populates="tracks")
scrobbles = relationship("Scrobble")