Files
MusicServer/internal/db/queries/song.sql
T
Sansan 0f552282f3 step 2: Add UUID columns with backfill and dual-write support
- Add migration 000007: Add UUID columns to soundtrack and song with backfill
- Update InsertSoundtrack and InsertSoundtrackWithExistingId to accept UUID
- Update AddSong to accept UUID
- Add dual-write: Go code now generates UUIDs for new records
- Add uuid and pgtype imports

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-01 22:40:21 +02:00

45 lines
1.1 KiB
SQL

-- name: ClearSongs :exec
DELETE FROM song;
-- name: ClearSongsBySoundtrackId :exec
DELETE FROM song WHERE soundtrack_id = $1;
-- name: AddSong :exec
INSERT INTO song(uuid, soundtrack_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5, $6);
-- name: CheckSong :one
SELECT COUNT(*) FROM song WHERE soundtrack_id = $1 AND path = $2;
-- name: CheckSongWithHash :one
SELECT COUNT(*) FROM song WHERE hash = $1;
-- name: GetSongWithHash :one
SELECT * FROM song WHERE hash = $1;
-- name: UpdateSong :exec
UPDATE song SET song_name=$1, file_name=$2, path=$3 where hash=$4;
-- name: AddHashToSong :exec
UPDATE song SET hash=$1 where soundtrack_id = $2 AND path = $3;
-- name: FindSongsFromSoundtrack :many
SELECT *
FROM song
WHERE soundtrack_id = $1;
-- name: AddSongPlayed :exec
UPDATE song SET times_played = times_played + 1
WHERE soundtrack_id = $1 AND song_name = $2;
-- name: FetchAllSongs :many
SELECT * FROM song;
-- name: GetSongById :one
SELECT * FROM song WHERE id = $1;
-- name: RemoveBrokenSong :exec
DELETE FROM song WHERE soundtrack_id = $1 AND path = $2;
-- name: RemoveBrokenSongs :exec
DELETE FROM song WHERE id = ANY($1);