builds again
This commit is contained in:
@@ -6,23 +6,18 @@ import (
|
||||
"git.eeqj.de/sneak/feta/instance"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
)
|
||||
|
||||
// NB that when you add a model below you must add it to this list!
|
||||
|
||||
func (m *Manager) doMigrations() {
|
||||
m.db.AutoMigrate(&apinstance{})
|
||||
}
|
||||
|
||||
type apinstance struct {
|
||||
type APInstance struct {
|
||||
gorm.Model
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
||||
UUID uuid.UUID `gorm:"type:uuid;primary_key;"`
|
||||
ErrorCount uint
|
||||
SuccessCount uint
|
||||
HighestID int
|
||||
Hostname string
|
||||
HighestID uint
|
||||
Hostname string `gorm:"type:varchar(100);unique_index"`
|
||||
Identified bool
|
||||
Fetching bool
|
||||
Disabled bool
|
||||
@@ -31,6 +26,68 @@ type apinstance struct {
|
||||
NodeInfoURL string
|
||||
ServerVersionString string
|
||||
ServerImplementationString string
|
||||
FSMState string
|
||||
}
|
||||
|
||||
// NB that when you add a model below you must add it to this list!
|
||||
func (m *Manager) doMigrations() {
|
||||
log.Info().Msg("doing database migrations if required")
|
||||
m.db.AutoMigrate(&APInstance{})
|
||||
}
|
||||
|
||||
func (m *Manager) SaveInstance(i *instance.Instance) error {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
var x APInstance
|
||||
if m.db.Where("UUID = ?", i.UUID).First(&x).RecordNotFound() {
|
||||
log.Info().
|
||||
Str("hostname", i.Hostname).
|
||||
Msg("instance not in db, inserting")
|
||||
// item does not exist in db yet, must insert
|
||||
ni := APInstance{
|
||||
UUID: i.UUID,
|
||||
Disabled: i.Disabled,
|
||||
ErrorCount: i.ErrorCount,
|
||||
FSMState: i.Status(),
|
||||
Fetching: i.Fetching,
|
||||
HighestID: i.HighestID,
|
||||
Hostname: i.Hostname,
|
||||
Identified: i.Identified,
|
||||
Implementation: string(i.Implementation),
|
||||
NextFetch: i.NextFetch,
|
||||
NodeInfoURL: i.NodeInfoURL,
|
||||
ServerImplementationString: i.ServerImplementationString,
|
||||
ServerVersionString: i.ServerVersionString,
|
||||
SuccessCount: i.SuccessCount,
|
||||
}
|
||||
r := m.db.Create(&ni)
|
||||
return r.Error
|
||||
} else {
|
||||
log.Info().
|
||||
Str("hostname", i.Hostname).
|
||||
Str("id", i.UUID.String()).
|
||||
Msg("instance found in db, updating")
|
||||
// exists in db, update db
|
||||
var ei APInstance
|
||||
// EI EI uh-oh
|
||||
m.db.Where("UUID = ?", i.UUID).First(&ei)
|
||||
ei.Disabled = i.Disabled
|
||||
ei.ErrorCount = i.ErrorCount
|
||||
ei.FSMState = i.Status()
|
||||
ei.Fetching = i.Fetching
|
||||
ei.HighestID = i.HighestID
|
||||
ei.Hostname = i.Hostname
|
||||
ei.Identified = i.Identified
|
||||
ei.Implementation = string(i.Implementation)
|
||||
ei.NextFetch = i.NextFetch
|
||||
ei.NodeInfoURL = i.NodeInfoURL
|
||||
ei.ServerImplementationString = i.ServerImplementationString
|
||||
ei.ServerVersionString = i.ServerVersionString
|
||||
ei.SuccessCount = i.SuccessCount
|
||||
|
||||
r := m.db.Save(&ei)
|
||||
return r.Error
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) ListInstances() ([]*instance.Instance, error) {
|
||||
|
||||
@@ -23,11 +23,11 @@ func New() *Manager {
|
||||
}
|
||||
|
||||
func (m *Manager) init() {
|
||||
m.open()
|
||||
m.db.LogMode(false)
|
||||
if viper.GetBool("Debug") {
|
||||
m.db.LogMode(true)
|
||||
}
|
||||
m.open()
|
||||
}
|
||||
|
||||
func mkdirp(p string) error {
|
||||
|
||||
Reference in New Issue
Block a user