3959c85111
New package internal/sync. LogChange writes a library_changes row inside the supplied tx. Encode helpers produce stable composite ids for like_* and playlist_track entries. Subsequent commits wire LogChange into the scanner / likes / playlists services. Also: dbtest.dataTables now includes library_changes so test isolation holds across runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
// Package sync supports the Flutter delta-sync endpoint by writing an
|
|
// append-only library_changes log alongside every mutation on tracked
|
|
// entities (artists, albums, tracks, likes, playlists, playlist_tracks).
|
|
//
|
|
// Callers MUST pass the same transaction that performed the underlying
|
|
// mutation — the change row and the mutation must commit or roll back
|
|
// together. See LogChange in changes.go.
|
|
package sync
|
|
|
|
// EntityType enumerates the entity kinds whose mutations are tracked
|
|
// by the library_changes log. Values must stay in sync with the CHECK
|
|
// constraint on library_changes.entity_type (migration 0025).
|
|
type EntityType string
|
|
|
|
const (
|
|
EntityArtist EntityType = "artist"
|
|
EntityAlbum EntityType = "album"
|
|
EntityTrack EntityType = "track"
|
|
EntityLikeTrack EntityType = "like_track"
|
|
EntityLikeAlbum EntityType = "like_album"
|
|
EntityLikeArtist EntityType = "like_artist"
|
|
EntityPlaylist EntityType = "playlist"
|
|
EntityPlaylistTrack EntityType = "playlist_track"
|
|
)
|
|
|
|
// Op is upsert or delete. Matches the CHECK constraint in migration 0025.
|
|
type Op string
|
|
|
|
const (
|
|
OpUpsert Op = "upsert"
|
|
OpDelete Op = "delete"
|
|
)
|
|
|
|
// Change is the wire shape returned by the sync endpoint to clients.
|
|
type Change struct {
|
|
ID int64 `json:"id"`
|
|
EntityType EntityType `json:"entity_type"`
|
|
EntityID string `json:"entity_id"`
|
|
Op Op `json:"op"`
|
|
}
|