summaryrefslogtreecommitdiff
path: root/src/hub/src/spreadspace.org/sfive/s5store.go
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:07:43 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:07:43 +0200
commit3fdd69ae1f2f02f0d54e73fb4bce7af81713fffd (patch)
treeaf9afc722430ff2e606082b5509e43ce39649169 /src/hub/src/spreadspace.org/sfive/s5store.go
parenthub: serve viz app under /viz (diff)
hub: Add per-DB UUID, optionally store in data-updates table
Diffstat (limited to 'src/hub/src/spreadspace.org/sfive/s5store.go')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 306cd1b..14d259f 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -6,6 +6,7 @@ import (
_ "github.com/mattn/go-sqlite3"
+ "code.google.com/p/go-uuid/uuid"
"github.com/coopernurse/gorp"
)
@@ -46,6 +47,8 @@ func dataUpdateFromStatisticsData(value StatisticsData) dataUpdateDb {
return dataUpdateDb{
-1,
-1,
+ value.SourceHubUuid,
+ value.SourceHubDataUpdateId,
value.StartTime.Unix(),
int64(value.Duration.Seconds()),
value.Data.ClientCount,
@@ -77,6 +80,7 @@ func initDb(path string) (res *gorp.DbMap, err error) {
dbmap.AddTableWithName(sourceDb{}, sourcesTn).SetKeys(true, "Id").SetUniqueTogether("ContentId", "Format", "Quality", "Hostname")
dbmap.AddTableWithName(clientDataDb{}, clientdataUpdatesTn).SetKeys(true, "Id")
dbmap.AddTableWithName(dataUpdateDb{}, dataUpdatesTn).SetKeys(true, "Id")
+ dbmap.AddTableWithName(hubInfoDb{}, hubInfoTn).SetKeys(false, "Name")
// TODO use some real migration, yadda yadda
err = dbmap.CreateTablesIfNotExists()
@@ -84,6 +88,16 @@ func initDb(path string) (res *gorp.DbMap, err error) {
return
}
+ oldid, err := dbmap.SelectStr("select Value from " + hubInfoTn + " where Name = 'HubUuid'")
+ // TODO handle only not-found this way
+ if err != nil || oldid == "" {
+ newid := uuid.New()
+ _, err = db.Exec("insert into "+hubInfoTn+" values ('HubUuid', ?)", newid)
+ if err != nil {
+ return
+ }
+ }
+
res = dbmap
return
}