add pointer for ids
This commit is contained in:
@@ -10,5 +10,5 @@ type CrudBase struct {
|
||||
}
|
||||
|
||||
type IDBase struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
ID *int `gorm:"primary_key"`
|
||||
}
|
||||
|
||||
@@ -2,19 +2,24 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
// q: why in tarnation are all the foreign keys pointers to ints?
|
||||
//
|
||||
// a: so they will be true sqlite null values instead of go zero
|
||||
// values when we save a row without that value
|
||||
|
||||
// Album represents the albums table
|
||||
type Album struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
AlbumArtist AlbumArtist
|
||||
AlbumArtistID int `gorm:"index" sql:"type:int REFERENCES album_artists(id) ON DELETE CASCADE"`
|
||||
AlbumArtistID *int `gorm:"index" sql:"type:int REFERENCES album_artists(id) ON DELETE CASCADE"`
|
||||
Title string `gorm:"not null;index"`
|
||||
// an Album having a `Path` is a little weird when browsing by tags
|
||||
// (for the most part - the library's folder structure is treated as
|
||||
// if it were flat), but this solves the "American Football problem"
|
||||
// https://en.wikipedia.org/wiki/American_Football_(band)#Discography
|
||||
Path string `gorm:"not null;unique_index"`
|
||||
CoverID int `sql:"type:int REFERENCES covers(id)"`
|
||||
CoverID *int `sql:"type:int REFERENCES covers(id)"`
|
||||
Cover Cover
|
||||
Year int
|
||||
Tracks []Track
|
||||
@@ -34,9 +39,9 @@ type Track struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Album Album
|
||||
AlbumID int `gorm:"index" sql:"type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
AlbumID *int `gorm:"index" sql:"type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
AlbumArtist AlbumArtist
|
||||
AlbumArtistID int `gorm:"index" sql:"type:int REFERENCES album_artists(id) ON DELETE CASCADE"`
|
||||
AlbumArtistID *int `gorm:"index" sql:"type:int REFERENCES album_artists(id) ON DELETE CASCADE"`
|
||||
Artist string
|
||||
Bitrate int
|
||||
Codec string
|
||||
@@ -51,7 +56,7 @@ type Track struct {
|
||||
ContentType string
|
||||
Size int
|
||||
Folder Folder
|
||||
FolderID int `gorm:"not null;index" sql:"type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
FolderID *int `gorm:"not null;index" sql:"type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Path string `gorm:"not null;unique_index"`
|
||||
}
|
||||
|
||||
@@ -85,11 +90,11 @@ type Setting struct {
|
||||
type Play struct {
|
||||
IDBase
|
||||
User User
|
||||
UserID int `gorm:"not null;index"`
|
||||
UserID *int `gorm:"not null;index"`
|
||||
Album Album
|
||||
AlbumID int `gorm:"not null;index"`
|
||||
AlbumID *int `gorm:"not null;index"`
|
||||
Folder Folder
|
||||
FolderID int `gorm:"not null;index"`
|
||||
FolderID *int `gorm:"not null;index"`
|
||||
Time time.Time
|
||||
Count int
|
||||
}
|
||||
@@ -101,8 +106,8 @@ type Folder struct {
|
||||
Name string
|
||||
Path string `gorm:"not null;unique_index"`
|
||||
Parent *Folder
|
||||
ParentID int
|
||||
CoverID int
|
||||
ParentID *int
|
||||
CoverID *int
|
||||
HasTracks bool `gorm:"not null;index"`
|
||||
Cover Cover
|
||||
IsNew bool `gorm:"-"`
|
||||
|
||||
Reference in New Issue
Block a user