feat(music-lab): Phase 1 DB 마이그레이션 + GenerateRequest 확장 + 커버이미지 엔드포인트
This commit is contained in:
@@ -83,6 +83,18 @@ def init_db() -> None:
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
|
||||
# Phase 1~3 신규 컬럼 마이그레이션
|
||||
for col, default in [
|
||||
("cover_images", "'[]'"),
|
||||
("wav_url", "''"),
|
||||
("video_url", "''"),
|
||||
("stem_urls", "'{}'"),
|
||||
]:
|
||||
try:
|
||||
conn.execute(f"ALTER TABLE music_library ADD COLUMN {col} TEXT NOT NULL DEFAULT {default}")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
|
||||
|
||||
# ── music_tasks CRUD ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -161,6 +173,10 @@ def _track_row_to_dict(r) -> Dict[str, Any]:
|
||||
"image_url": r["image_url"] if "image_url" in keys else "",
|
||||
"suno_id": r["suno_id"] if "suno_id" in keys else "",
|
||||
"file_hash": r["file_hash"] if "file_hash" in keys else "",
|
||||
"cover_images": json.loads(r["cover_images"]) if "cover_images" in keys and r["cover_images"] else [],
|
||||
"wav_url": r["wav_url"] if "wav_url" in keys else "",
|
||||
"video_url": r["video_url"] if "video_url" in keys else "",
|
||||
"stem_urls": json.loads(r["stem_urls"]) if "stem_urls" in keys and r["stem_urls"] else {},
|
||||
"created_at": r["created_at"],
|
||||
}
|
||||
|
||||
@@ -300,6 +316,26 @@ def update_lyrics(lyrics_id: int, data: Dict[str, Any]) -> Optional[Dict[str, An
|
||||
return _lyrics_row_to_dict(row) if row else None
|
||||
|
||||
|
||||
def update_track_cover_images(track_id: int, images: list) -> None:
|
||||
with _conn() as conn:
|
||||
conn.execute("UPDATE music_library SET cover_images=? WHERE id=?", (json.dumps(images), track_id))
|
||||
|
||||
|
||||
def update_track_wav_url(track_id: int, wav_url: str) -> None:
|
||||
with _conn() as conn:
|
||||
conn.execute("UPDATE music_library SET wav_url=? WHERE id=?", (wav_url, track_id))
|
||||
|
||||
|
||||
def update_track_video_url(track_id: int, video_url: str) -> None:
|
||||
with _conn() as conn:
|
||||
conn.execute("UPDATE music_library SET video_url=? WHERE id=?", (video_url, track_id))
|
||||
|
||||
|
||||
def update_track_stem_urls(track_id: int, stems: dict) -> None:
|
||||
with _conn() as conn:
|
||||
conn.execute("UPDATE music_library SET stem_urls=? WHERE id=?", (json.dumps(stems), track_id))
|
||||
|
||||
|
||||
def delete_lyrics(lyrics_id: int) -> bool:
|
||||
with _conn() as conn:
|
||||
row = conn.execute("SELECT id FROM saved_lyrics WHERE id = ?", (lyrics_id,)).fetchone()
|
||||
|
||||
Reference in New Issue
Block a user