feat(10-01): update SQL schema files for multi-library fresh installs
- Create _libraries.sql with libraries table (name, path, created_at) - Add library_id FK column and index to audio_files.sql - Update playlist_tracks.sql with nullable audio_file_id, SET NULL FK, and 6 phantom columns - Add af.library_id to track_metadata VIEW - Regenerate sqlc code for updated schemas - Fix playlist.go to use sql.NullInt64 for nullable audio_file_id
This commit is contained in:
@@ -24,7 +24,7 @@ func (q *Queries) CountAudioFiles(ctx context.Context) (int64, error) {
|
||||
|
||||
const createAudioFile = `-- name: CreateAudioFile :one
|
||||
INSERT INTO audio_files (file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
RETURNING id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename
|
||||
RETURNING id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename, library_id
|
||||
`
|
||||
|
||||
type CreateAudioFileParams struct {
|
||||
@@ -66,6 +66,7 @@ func (q *Queries) CreateAudioFile(ctx context.Context, arg CreateAudioFileParams
|
||||
&i.Bitrate,
|
||||
&i.FileSize,
|
||||
&i.Basename,
|
||||
&i.LibraryID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func (q *Queries) GetAllAudioFilePaths(ctx context.Context) ([]GetAllAudioFilePa
|
||||
}
|
||||
|
||||
const getAllAudioFiles = `-- name: GetAllAudioFiles :many
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename FROM audio_files
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename, library_id FROM audio_files
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllAudioFiles(ctx context.Context) ([]AudioFile, error) {
|
||||
@@ -146,6 +147,7 @@ func (q *Queries) GetAllAudioFiles(ctx context.Context) ([]AudioFile, error) {
|
||||
&i.Bitrate,
|
||||
&i.FileSize,
|
||||
&i.Basename,
|
||||
&i.LibraryID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -307,7 +309,7 @@ func (q *Queries) GetAllTracksWithFullMetadata(ctx context.Context) ([]GetAllTra
|
||||
}
|
||||
|
||||
const getAudioFile = `-- name: GetAudioFile :one
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename FROM audio_files
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename, library_id FROM audio_files
|
||||
WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
@@ -326,12 +328,13 @@ func (q *Queries) GetAudioFile(ctx context.Context, id int64) (AudioFile, error)
|
||||
&i.Bitrate,
|
||||
&i.FileSize,
|
||||
&i.Basename,
|
||||
&i.LibraryID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAudioFileByPath = `-- name: GetAudioFileByPath :one
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename FROM audio_files
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename, library_id FROM audio_files
|
||||
WHERE file_path = ? LIMIT 1
|
||||
`
|
||||
|
||||
@@ -350,6 +353,7 @@ func (q *Queries) GetAudioFileByPath(ctx context.Context, filePath string) (Audi
|
||||
&i.Bitrate,
|
||||
&i.FileSize,
|
||||
&i.Basename,
|
||||
&i.LibraryID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -448,7 +452,7 @@ func (q *Queries) GetAudioFilesByReleaseGroup(ctx context.Context, releaseGroupI
|
||||
}
|
||||
|
||||
const getAudioFilesNeedingMetadata = `-- name: GetAudioFilesNeedingMetadata :many
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename FROM audio_files
|
||||
SELECT id, file_path, length_milliseconds, file_type_id, recording_id, sample_rate, bit_depth, channels, bitrate, file_size, basename, library_id FROM audio_files
|
||||
WHERE recording_id = 0
|
||||
`
|
||||
|
||||
@@ -473,6 +477,7 @@ func (q *Queries) GetAudioFilesNeedingMetadata(ctx context.Context) ([]AudioFile
|
||||
&i.Bitrate,
|
||||
&i.FileSize,
|
||||
&i.Basename,
|
||||
&i.LibraryID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ type AudioFile struct {
|
||||
Bitrate int64
|
||||
FileSize int64
|
||||
Basename string
|
||||
LibraryID int64
|
||||
}
|
||||
|
||||
type CoverArt struct {
|
||||
@@ -56,6 +57,13 @@ type Genre struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type Library struct {
|
||||
ID int64
|
||||
Name string
|
||||
Path string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type PlayerState struct {
|
||||
ID int64
|
||||
Volume int64
|
||||
@@ -72,10 +80,16 @@ type Playlist struct {
|
||||
}
|
||||
|
||||
type PlaylistTrack struct {
|
||||
ID int64
|
||||
PlaylistID int64
|
||||
AudioFileID int64
|
||||
Position int64
|
||||
ID int64
|
||||
PlaylistID int64
|
||||
AudioFileID sql.NullInt64
|
||||
Position int64
|
||||
PhantomTitle sql.NullString
|
||||
PhantomArtist sql.NullString
|
||||
PhantomAlbum sql.NullString
|
||||
PhantomDurationMs sql.NullInt64
|
||||
PhantomGenre sql.NullString
|
||||
PhantomCoverArtPath sql.NullString
|
||||
}
|
||||
|
||||
type Queue struct {
|
||||
@@ -155,4 +169,5 @@ type TrackMetadatum struct {
|
||||
Channels int64
|
||||
Bitrate int64
|
||||
FileSize int64
|
||||
LibraryID int64
|
||||
}
|
||||
|
||||
@@ -7,16 +7,17 @@ package sqlcgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const addPlaylistTrack = `-- name: AddPlaylistTrack :one
|
||||
INSERT INTO playlist_tracks (playlist_id, audio_file_id, position) VALUES (?, ?, ?)
|
||||
RETURNING id, playlist_id, audio_file_id, position
|
||||
RETURNING id, playlist_id, audio_file_id, position, phantom_title, phantom_artist, phantom_album, phantom_duration_ms, phantom_genre, phantom_cover_art_path
|
||||
`
|
||||
|
||||
type AddPlaylistTrackParams struct {
|
||||
PlaylistID int64
|
||||
AudioFileID int64
|
||||
AudioFileID sql.NullInt64
|
||||
Position int64
|
||||
}
|
||||
|
||||
@@ -28,6 +29,12 @@ func (q *Queries) AddPlaylistTrack(ctx context.Context, arg AddPlaylistTrackPara
|
||||
&i.PlaylistID,
|
||||
&i.AudioFileID,
|
||||
&i.Position,
|
||||
&i.PhantomTitle,
|
||||
&i.PhantomArtist,
|
||||
&i.PhantomAlbum,
|
||||
&i.PhantomDurationMs,
|
||||
&i.PhantomGenre,
|
||||
&i.PhantomCoverArtPath,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -116,7 +123,7 @@ ORDER BY pt.playlist_id, pt.position
|
||||
type GetAllPlaylistTracksWithMetadataRow struct {
|
||||
ID int64
|
||||
PlaylistID int64
|
||||
AudioFileID int64
|
||||
AudioFileID sql.NullInt64
|
||||
Position int64
|
||||
FilePath string
|
||||
LengthMilliseconds int64
|
||||
@@ -262,7 +269,7 @@ ORDER BY pt.position
|
||||
type GetPlaylistTracksRow struct {
|
||||
ID int64
|
||||
PlaylistID int64
|
||||
AudioFileID int64
|
||||
AudioFileID sql.NullInt64
|
||||
Position int64
|
||||
FilePath string
|
||||
}
|
||||
@@ -326,7 +333,7 @@ ORDER BY pt.position
|
||||
type GetPlaylistTracksWithMetadataRow struct {
|
||||
ID int64
|
||||
PlaylistID int64
|
||||
AudioFileID int64
|
||||
AudioFileID sql.NullInt64
|
||||
Position int64
|
||||
FilePath string
|
||||
LengthMilliseconds int64
|
||||
|
||||
Reference in New Issue
Block a user