Add 'saved_track_data'

Anna Schumaker 2023-05-10 17:36:34 -04:00
parent aa7e5c4442
commit 6a55c6088d

17
saved_track_data.md Normal file

@ -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 |