| |
| """Seed the database with initial data for consistent Docker builds.""" |
|
|
| import json |
| import os |
| from database import ( |
| init_database, |
| add_song, add_user, add_playlist, add_memory, add_context, |
| get_all_songs, get_all_users |
| ) |
| from semantic_search import ( |
| add_song_vibe, add_memory_vibe, add_context_vibe, add_playlist_journey |
| ) |
|
|
|
|
| def seed_database(): |
| """Initialize and seed the database with sample data.""" |
| |
| |
| print("π¦ Initializing database...") |
| init_database() |
| |
| |
| if get_all_songs(): |
| print("β
Database already seeded, skipping...") |
| return |
| |
| print("π± Seeding database...") |
| |
| |
| songs_data = [ |
| {"title": "Bohemian Rhapsody", "artist": "Queen", "album": "A Night at the Opera", "duration": 354, "bpm": 72, "energy_level": 8, "lyrics": "Is this the real life? Is this just fantasy? Caught in a landslide, no escape from reality"}, |
| {"title": "Imagine", "artist": "John Lennon", "album": "Imagine", "duration": 183, "bpm": 75, "energy_level": 3, "lyrics": "Imagine there's no heaven, it's easy if you try, no hell below us, above us only sky"}, |
| {"title": "Blinding Lights", "artist": "The Weeknd", "album": "After Hours", "duration": 200, "bpm": 171, "energy_level": 9, "lyrics": "I've been on my own for long enough, maybe you can show me how to love, maybe"}, |
| {"title": "Someone Like You", "artist": "Adele", "album": "21", "duration": 285, "bpm": 67, "energy_level": 4, "lyrics": "I heard that you're settled down, that you found a girl and you're married now"}, |
| {"title": "Uptown Funk", "artist": "Mark Ronson ft. Bruno Mars", "album": "Uptown Special", "duration": 269, "bpm": 115, "energy_level": 10, "lyrics": "This hit, that ice cold, Michelle Pfeiffer, that white gold"}, |
| {"title": "Fix You", "artist": "Coldplay", "album": "X&Y", "duration": 295, "bpm": 138, "energy_level": 5, "lyrics": "When you try your best but you don't succeed, when you get what you want but not what you need"}, |
| {"title": "Lose Yourself", "artist": "Eminem", "album": "8 Mile", "duration": 326, "bpm": 86, "energy_level": 9, "lyrics": "Look, if you had one shot or one opportunity, to seize everything you ever wanted"}, |
| {"title": "Let It Be", "artist": "The Beatles", "album": "Let It Be", "duration": 243, "bpm": 75, "energy_level": 3, "lyrics": "When I find myself in times of trouble, Mother Mary comes to me"}, |
| {"title": "Rolling in the Deep", "artist": "Adele", "album": "21", "duration": 228, "bpm": 105, "energy_level": 7, "lyrics": "There's a fire starting in my heart, I'm reaching for every high and low"}, |
| {"title": "Happy", "artist": "Pharrell Williams", "album": "G I R L", "duration": 232, "bpm": 160, "energy_level": 10, "lyrics": "It might seem crazy what I'm about to say, sunshine she's here, you can take a guess"}, |
| ] |
| |
| print("π΅ Adding songs...") |
| for song in songs_data: |
| lyrics = song.pop("lyrics") |
| added_song = add_song(**song) |
| add_song_vibe(added_song["id"], song["title"], song["artist"], lyrics) |
| |
| |
| users_data = ["Alice", "Bob", "Charlie", "Diana", "Eve"] |
| |
| print("π€ Adding users...") |
| for name in users_data: |
| add_user(name) |
| |
| |
| playlists_data = [ |
| {"name": "Rainy Day Vibes", "vibe_code": "chill_melancholy", "mood": "Perfect for cloudy afternoons when you want to feel your feelings"}, |
| {"name": "Workout Energy", "vibe_code": "high_energy", "mood": "Maximum pump-up tracks for crushing your fitness goals"}, |
| {"name": "Late Night Coding", "vibe_code": "focus_calm", "mood": "Deep focus music for those 3am debugging sessions"}, |
| {"name": "Road Trip Classics", "vibe_code": "adventure_fun", "mood": "Windows down, volume up, endless highway ahead"}, |
| {"name": "Heartbreak Recovery", "vibe_code": "sad_to_healing", "mood": "Journey from tears to acceptance, one song at a time"}, |
| ] |
| |
| print("π΅ Adding playlists...") |
| for pl in playlists_data: |
| mood = pl.pop("mood") |
| added_pl = add_playlist(**pl) |
| add_playlist_journey(added_pl["id"], pl["name"], mood) |
| |
| |
| contexts_data = [ |
| {"weather": "rainy", "time_of_day": "night", "location_type": "home"}, |
| {"weather": "sunny", "time_of_day": "morning", "location_type": "car"}, |
| {"weather": "cloudy", "time_of_day": "afternoon", "location_type": "office"}, |
| {"weather": "clear", "time_of_day": "evening", "location_type": "gym"}, |
| {"weather": "stormy", "time_of_day": "night", "location_type": "home"}, |
| ] |
| |
| print("π€οΈ Adding contexts...") |
| for ctx in contexts_data: |
| added_ctx = add_context(**ctx) |
| add_context_vibe(added_ctx["id"], ctx.get("weather", ""), ctx.get("time_of_day", ""), ctx.get("location_type", "")) |
| |
| |
| memories_data = [ |
| {"user_id": 1, "description": "First dance at my wedding, perfect song for the perfect moment", "date": "2024-06-15"}, |
| {"user_id": 1, "description": "Road trip to the coast with friends, singing at the top of our lungs", "date": "2024-07-20"}, |
| {"user_id": 2, "description": "Studying for finals, this song kept me going through the night", "date": "2024-03-10"}, |
| {"user_id": 2, "description": "Running my first 5K, this was my power song at the finish line", "date": "2024-05-01"}, |
| {"user_id": 3, "description": "Grandma's funeral, this song made everyone cry but also smile", "date": "2023-11-30"}, |
| ] |
| |
| print("π Adding memories...") |
| for mem in memories_data: |
| added_mem = add_memory(**mem) |
| add_memory_vibe(added_mem["id"], mem["user_id"], mem["description"]) |
| |
| print("\nβ
Database seeded successfully!") |
| print(f" - {len(songs_data)} songs") |
| print(f" - {len(users_data)} users") |
| print(f" - {len(playlists_data)} playlists") |
| print(f" - {len(contexts_data)} contexts") |
| print(f" - {len(memories_data)} memories") |
|
|
|
|
| if __name__ == "__main__": |
| seed_database() |
|
|