merge album and folder models
This commit is contained in:
117
model/model.go
117
model/model.go
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// q: what in tarnation are the `IsNew`s for?
|
||||
// a: it's a bit of a hack - but we set a models IsNew to true if
|
||||
@@ -9,108 +11,73 @@ import "time"
|
||||
// that bool being true - since it won't be true if it was already
|
||||
// in the db
|
||||
|
||||
// Album represents the albums table
|
||||
type Album struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Artist Artist
|
||||
ArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES 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:"default: null; type:int REFERENCES covers(id)"`
|
||||
Cover Cover
|
||||
Year int
|
||||
Tracks []Track
|
||||
IsNew bool `gorm:"-"`
|
||||
}
|
||||
|
||||
// Artist represents the Artists table
|
||||
type Artist struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Name string `gorm:"not null; unique_index"`
|
||||
Albums []Album
|
||||
Name string `gorm:"not null; unique_index"`
|
||||
Folders []Folder
|
||||
}
|
||||
|
||||
// Track represents the tracks table
|
||||
type Track struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Album Album
|
||||
AlbumID int `gorm:"index" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
Artist Artist
|
||||
ArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
TrackArtist string
|
||||
Bitrate int
|
||||
Codec string
|
||||
DiscNumber int
|
||||
Duration int
|
||||
Title string
|
||||
TotalDiscs int
|
||||
TotalTracks int
|
||||
TrackNumber int
|
||||
Year int
|
||||
Suffix string
|
||||
ContentType string
|
||||
Size int
|
||||
Folder Folder
|
||||
FolderID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Path string `gorm:"not null; unique_index"`
|
||||
Folder Folder
|
||||
// TODO: try removing idx_folder_basename_ext
|
||||
FolderID int `gorm:"not null; unique_index:idx_folder_filename_ext" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Filename string `gorm:"not null; unique_index:idx_folder_filename_ext" sql:"default: null"`
|
||||
Ext string `gorm:"not nill; unique_index:idx_folder_filename_ext" sql:"default: null"`
|
||||
Artist Artist
|
||||
ArtistID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
ContentType string `gorm:"not null" sql:"default: null"`
|
||||
Duration int `gorm:"not null" sql:"default: null"`
|
||||
Size int `gorm:"not null" sql:"default: null"`
|
||||
Bitrate int `gorm:"not null" sql:"default: null"`
|
||||
TagDiscNumber int `sql:"default: null"`
|
||||
TagTitle string `sql:"default: null"`
|
||||
TagTotalDiscs int `sql:"default: null"`
|
||||
TagTotalTracks int `sql:"default: null"`
|
||||
TagTrackArtist string `sql:"default: null"`
|
||||
TagTrackNumber int `sql:"default: null"`
|
||||
TagYear int `sql:"default: null"`
|
||||
}
|
||||
|
||||
// Cover represents the covers table
|
||||
type Cover struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Image []byte
|
||||
Path string `gorm:"not null; unique_index"`
|
||||
IsNew bool `gorm:"-"`
|
||||
}
|
||||
|
||||
// User represents the users table
|
||||
type User struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Name string `gorm:"not null; unique_index"`
|
||||
Password string
|
||||
LastFMSession string
|
||||
IsAdmin bool
|
||||
Name string `gorm:"not null; unique_index" sql:"default: null"`
|
||||
Password string `gorm:"not null" sql:"default: null"`
|
||||
LastFMSession string `sql:"default: null"`
|
||||
IsAdmin bool `sql:"default: null"`
|
||||
}
|
||||
|
||||
// Setting represents the settings table
|
||||
type Setting struct {
|
||||
CrudBase
|
||||
Key string `gorm:"primary_key; auto_increment:false"`
|
||||
Value string
|
||||
Key string `gorm:"not null; primary_key; auto_increment:false" sql:"default: null"`
|
||||
Value string `sql:"default: null"`
|
||||
}
|
||||
|
||||
// Play represents the settings table
|
||||
type Play struct {
|
||||
IDBase
|
||||
User User
|
||||
UserID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"`
|
||||
Album Album
|
||||
AlbumID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
|
||||
Folder Folder
|
||||
FolderID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Time time.Time
|
||||
FolderID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
Time time.Time `sql:"default: null"`
|
||||
Count int
|
||||
}
|
||||
|
||||
// Folder represents the settings table
|
||||
type Folder struct {
|
||||
IDBase
|
||||
CrudBase
|
||||
Name string
|
||||
Path string `gorm:"not null; unique_index"`
|
||||
Parent *Folder
|
||||
ParentID int `sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
CoverID int `sql:"default: null; type:int REFERENCES covers(id)"`
|
||||
HasTracks bool `gorm:"not null; index"`
|
||||
Cover Cover
|
||||
IsNew bool `gorm:"-"`
|
||||
LeftPath string `gorm:"unique_index:idx_left_path_right_path"`
|
||||
RightPath string `gorm:"not null; unique_index:idx_left_path_right_path" sql:"default: null"`
|
||||
Parent *Folder
|
||||
ParentID int `sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"`
|
||||
AlbumArtist Artist
|
||||
AlbumArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
AlbumTitle string `gorm:"index" sql:"default: null"`
|
||||
AlbumYear int `sql:"default: null"`
|
||||
Cover string `sql:"default: null"`
|
||||
Tracks []Track
|
||||
IsNew bool `gorm:"-"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user