Skip to content
Snippets Groups Projects
Commit 33f090f8 authored by Christian Pointner's avatar Christian Pointner
Browse files

added description field to playlist

parent 32c7d9b2
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ package store ...@@ -26,6 +26,7 @@ package store
import ( import (
"errors" "errors"
"time"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"gopkg.in/gormigrate.v1" "gopkg.in/gormigrate.v1"
...@@ -72,6 +73,24 @@ func (st *Store) initDBModel() (err error) { ...@@ -72,6 +73,24 @@ func (st *Store) initDBModel() (err error) {
Migrate: func(tx *gorm.DB) error { return nil }, Migrate: func(tx *gorm.DB) error { return nil },
Rollback: func(tx *gorm.DB) error { return nil }, Rollback: func(tx *gorm.DB) error { return nil },
}, },
{
ID: "201905160033",
Migrate: func(tx *gorm.DB) error {
type Playlist struct {
ID uint64 `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"`
Description string `json:"description"`
ShowName string `json:"show" gorm:"not null;index"`
Show Show `json:"-" gorm:"association_foreignkey:Name"`
Entries []PlaylistEntry `json:"entries,omitempty"`
}
return tx.AutoMigrate(&Playlist{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Table("playlists").DropColumn("description").Error
},
},
}) })
m.InitSchema(initialMigration) m.InitSchema(initialMigration)
...@@ -79,7 +98,7 @@ func (st *Store) initDBModel() (err error) { ...@@ -79,7 +98,7 @@ func (st *Store) initDBModel() (err error) {
return errors.New("running database migrations failed: " + err.Error()) return errors.New("running database migrations failed: " + err.Error())
} }
if err = st.db.Table(migrationsTn).Select("id").Order("id").Limit(1).Row().Scan(&st.revision); err != nil { if err = st.db.Table(migrationsTn).Select("id").Order("id DESC").Limit(1).Row().Scan(&st.revision); err != nil {
return errors.New("fetching current database revision failed: " + err.Error()) return errors.New("fetching current database revision failed: " + err.Error())
} }
return return
......
...@@ -191,12 +191,13 @@ type PlaylistEntry struct { ...@@ -191,12 +191,13 @@ type PlaylistEntry struct {
} }
type Playlist struct { type Playlist struct {
ID uint64 `json:"id" gorm:"primary_key"` ID uint64 `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created"` CreatedAt time.Time `json:"created"`
UpdatedAt time.Time `json:"updated"` UpdatedAt time.Time `json:"updated"`
ShowName string `json:"show" gorm:"not null;index"` Description string `json:"description"`
Show Show `json:"-" gorm:"association_foreignkey:Name"` ShowName string `json:"show" gorm:"not null;index"`
Entries []PlaylistEntry `json:"entries,omitempty"` Show Show `json:"-" gorm:"association_foreignkey:Name"`
Entries []PlaylistEntry `json:"entries,omitempty"`
} }
type Playlists []Playlist type Playlists []Playlist
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment