diff --git a/cmd/migrate.go b/cmd/migrate.go index afb6343..8ad8ecd 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -102,10 +102,14 @@ func init() { func sysRegister(mac string, site string, user string, pass string) { + host, err := os.Hostname() + if err != nil { + log.Fatal(err) + } sys := map[string]interface{}{ "clientVersion": "1.2.0", "name": "migration", - "hostname": os.Hostname(), + "hostname": host, "mac": mac, } payloadBytes, err := json.Marshal(sys) diff --git a/internal/db.go b/internal/db.go index fb037c5..2405825 100644 --- a/internal/db.go +++ b/internal/db.go @@ -95,7 +95,7 @@ func dbInit() { gormdb.AutoMigrate(&Command{}) gormdb.AutoMigrate(&System{}) //TODO: ensure these are the most efficient indexes - gormdb.Model(&User{}).AddIndex("idx_user", "username") + gormdb.Model(&User{}).AddUniqueIndex("idx_user", "username") gormdb.Model(&System{}).AddIndex("idx_mac", "mac") gormdb.Model(&Command{}).AddIndex("idx_exit_command_created", "exit_status, created, command") gormdb.Model(&Command{}).AddIndex("idx_user_exit_command_created", "user_id, exit_status, created, command") diff --git a/internal/server.go b/internal/server.go index 182c5ea..26492f1 100644 --- a/internal/server.go +++ b/internal/server.go @@ -111,6 +111,7 @@ func loggerWithFormatterWriter(f gin.LogFormatter) gin.HandlerFunc { }) } + // Run starts server func Run() { // Initialize backend