Skip to content

Commit

Permalink
fixed sqlite - test all for each database
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Jul 3, 2018
1 parent 4c09c11 commit df69164
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:

env:
global:
- VERSION=0.28.6
- VERSION=0.28.7
- DB_HOST=localhost
- DB_USER=travis
- DB_PASS=
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:latest

ENV VERSION=v0.28.6
ENV VERSION=v0.28.7

RUN apk --no-cache add libstdc++ ca-certificates
RUN wget -q https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \
Expand Down
2 changes: 1 addition & 1 deletion core/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func CreateDatabase() {
sql := "postgres_up.sql"
if dbServer == "mysql" {
sql = "mysql_up.sql"
} else if dbServer == "sqlite3" {
} else if dbServer == "sqlite" {
sql = "sqlite_up.sql"
}
up, _ := SqlBox.String(sql)
Expand Down
8 changes: 8 additions & 0 deletions core/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ func (s *Service) GraphData() string {
var d []DateScan
increment := "minute"
since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0)

// this function needs some work, asap
sql := fmt.Sprintf("SELECT date_trunc('%v', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", increment, s.Id, since.Format(time.RFC3339))
if dbServer == "mysql" {
sql = fmt.Sprintf("SELECT created_at, AVG(latency)*1000 AS VALUE FROM hits WHERE service=%v GROUP BY 1 ORDER BY created_at ASC;", s.Id)
} else if dbServer == "sqlite" {
sql = fmt.Sprintf("SELECT created_at, AVG(latency)*1000 AS VALUE FROM hits WHERE service=%v GROUP BY 1 ORDER BY created_at ASC;", s.Id)
}

dated, err := DbSession.Query(db.Raw(sql))
if err != nil {
utils.Log(2, err)
Expand Down
26 changes: 21 additions & 5 deletions core/setup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"fmt"
"github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils"
"os"
Expand Down Expand Up @@ -77,17 +78,32 @@ func LoadSampleData() error {
Method: "POST",
PostData: `{ "title": "statup", "body": "bar", "userId": 19999 }`,
}
s1.Create()
s2.Create()
s3.Create()
s4.Create()
id, err := s1.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s2.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s3.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}
id, err = s4.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Service %v: %v", id, err))
}

checkin := &Checkin{
Service: s2.Id,
Interval: 30,
Api: utils.NewSHA1Hash(18),
}
checkin.Create()
id, err = checkin.Create()
if err != nil {
utils.Log(3, fmt.Sprintf("Error creating Checkin %v: %v", id, err))
}

//for i := 0; i < 3; i++ {
// s1.Check()
Expand Down
2 changes: 1 addition & 1 deletion handlers/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import (
func Error404Handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
ExecuteResponse(w, r, "error_404.html", nil)
}
}
2 changes: 0 additions & 2 deletions handlers/settings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handlers

import (
"fmt"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/notifications"
"github.com/hunterlong/statup/types"
Expand All @@ -25,7 +24,6 @@ func PluginsHandler(w http.ResponseWriter, r *http.Request) {
//}

//CoreApp.PluginFields = pluginFields
fmt.Println(core.CoreApp.Communications)

ExecuteResponse(w, r, "settings.html", core.CoreApp)
}
Expand Down
Loading

0 comments on commit df69164

Please sign in to comment.