diff --git a/backend/__pycache__/config.cpython-312.pyc b/backend/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000..fd64420 Binary files /dev/null and b/backend/__pycache__/config.cpython-312.pyc differ diff --git a/backend/main.py b/backend/app.py similarity index 100% rename from backend/main.py rename to backend/app.py diff --git a/backend/db.py b/backend/db.py index 998f5ac..6c9f44e 100644 --- a/backend/db.py +++ b/backend/db.py @@ -1,4 +1,5 @@ from config import db +from datetime import datetime # Association tables song_artist = db.Table( @@ -13,17 +14,57 @@ db.Column('genre_id', db.Integer, db.ForeignKey('genres.id'), primary_key=True) ) +class Playlist(db.Model): + __tablename__ = "playlists" + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + spotify_playlist_id = db.Column(db.String(100), nullable=False) + name = db.Column(db.String(200), nullable=False) + description = db.Column(db.Text, nullable=True) + user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) + created_at = db.Column(db.DateTime, default=datetime.utcnow) + + + + #relationships + user = db.relationship('User', back_populates='playlist') + songs = db.relationship('Song', back_populates='playlist') + recommendations = db.relationship('Recommendation') class Song(db.Model): - __tablename__ = "Songs" + __tablename__ = "songs" id = db.Column(db.Integer, primary_key=True, autoincrement=True) - tempo = db.Column(db.Integer, nullable=False) + spotify_id = db.Column(db.String(100), unique=True, nullable=False) + name = db.Column(db.String(200), nullable=False) + + # Audio features for Gemini analysis + tempo = db.Column(db.Float, nullable=True) + danceability = db.Column(db.Float, nullable=True) + energy = db.Column(db.Float, nullable=True) + valence = db.Column(db.Float, nullable=True) + acousticness = db.Column(db.Float, nullable=True) + instrumentalness = db.Column(db.Float, nullable=True) + liveness = db.Column(db.Float, nullable=True) + loudness = db.Column(db.Float, nullable=True) + speechiness = db.Column(db.Float, nullable=True) + key = db.Column(db.Integer, nullable=True) + mode = db.Column(db.Integer, nullable=True) + time_signature = db.Column(db.Integer, nullable=True) + + created_at = db.Column(db.DateTime, default=datetime.utcnow) + + # One-to-many relationship with playlist + playlist_id = db.Column(db.Integer, db.ForeignKey('playlists.id'), nullable=False) + playlist = db.relationship('Playlist', back_populates='songs') + + # Many-to-many relationships artists = db.relationship('Artist', secondary=song_artist, back_populates='songs') genres = db.relationship('Genre', secondary=song_genre, back_populates='songs') class Artist(db.Model): __tablename__ = "artists" id = db.Column(db.Integer, primary_key=True, autoincrement=True) - name = db.Column(db.String, nullable=False) + spotify_id = db.Column(db.String(100), unique=True, nullable=False) + name = db.Column(db.String(200), nullable=False) + #Many to many songs = db.relationship('Song', secondary=song_artist, back_populates='artists') class Genre(db.Model): @@ -31,3 +72,16 @@ class Genre(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String, nullable=False) songs = db.relationship('Song', secondary=song_genre, back_populates='genres') + +class Recommendation(db.Model): + __tablename__ = "recommendations" + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + playlist_id = db.Column(db.Integer, db.ForeignKey('playlists.id'), nullable=False) + seed_song_id = db.Column(db.Integer, db.ForeignKey('songs.id'), nullable=False) + recommended_song_id = db.Column(db.Integer, db.ForeignKey('songs.id'), nullable=False) + created_at = db.Column(db.DateTime, default=datetime.utcnow) + + # Relationships + playlist = db.relationship('Playlist', back_populates='recommendations') + seed_song = db.relationship('Song', foreign_keys=[seed_song_id]) + recommended_song = db.relationship('Song', foreign_keys=[recommended_song_id])