diff --git a/saved_track_data.md b/saved_track_data.md new file mode 100644 index 0000000..3e0479a --- /dev/null +++ b/saved_track_data.md @@ -0,0 +1,17 @@ +The `saved_track_data` table is used to preserve [track](tracks) data when tracks are deleted and restore the values if a track with the same mbid is later added. This lets us handle renaming files without losing the user's playback statistics. Note that this only works for tracks that have an MBID. + +### Columns + +| Name | Type | Default | Description | +| ----------- | --------- | ------- | ------------------------------------------------------------------------------------- | +| mbid | TEXT | | The [MusicBrainz ID](https://musicbrainz.org/doc/MusicBrainz_Identifier) of the track | +| favorite | BOOLEAN | FALSE | The favorite status of the track | +| playcount | INTEGER | 0 | The playcount of the track | +| lastplayed | TIMESTAMP | NULL | The last played timestamp of the track | +| laststarted | TIMESTAMP | NULL | The last started timestamp of the track | + +### Triggers +| Name | When | Description | +| --------------------- | ------------- | ------------------------------------------------------------------ | +| tracks_delete_save | Before delete | Insert the appropriate fields into the saved_tracks_data table | +| tracks_insert_restore | After insert | Update the [[tracks]] table with fields from the saved_tracks_data | \ No newline at end of file