Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaiaroto committed Oct 23, 2014
1 parent b65691f commit 49db876
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
8 changes: 8 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Best efforts will be made to keep this up to date, but there are no guarantees b
This file will log major feature advancements and bug fixes. Not quite everything will be noted (especially at first).
Please check GitHub issues.

## 0.12.1
-------------

Fixing an issue with configuration where Postgres connection would be closed after configuring the database. It now will
be closed once the application exits (like before). Fixing a SQL create table script as well.

Added an API endpoint to test the connection to the Postgres database. Will need to do the same for InfluxDB.

## 0.12.0
-------------

Expand Down
20 changes: 20 additions & 0 deletions lib/config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,23 @@ func (database *SocialHarvestDB) StoreRow(row interface{}) {
}

}

// Checks access to the database
func (database *SocialHarvestDB) HasAccess() bool {
var err error

if database.Postgres != nil {
var c int
err = database.Postgres.Get(&c, "SELECT COUNT(*) FROM messages")
if err == nil {
return true
} else {
return false
}
}
if database.InfluxDB != nil {

}

return false
}
39 changes: 34 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"strconv"
)

var appVersion = "0.12.0-preview"
var appVersion = "0.12.1-preview"
var confFile string
var socialHarvest = config.SocialHarvest{}

Expand Down Expand Up @@ -150,6 +150,34 @@ func WriteSocialHarvestConfig(w rest.ResponseWriter, r *rest.Request) {
w.WriteJson(res.End())
}

// Returns information about the currently configured database, if it's reachable, etc.
func DatabaseInfo(w rest.ResponseWriter, r *rest.Request) {
res := config.NewHypermediaResource()
res.Links["database:info"] = config.HypermediaLink{
Href: "/database/info",
}

if socialHarvest.Database.Postgres != nil {
res.Data["type"] = "postgres"
// SELECT * FROM has_database_privilege('username', 'database', 'connect');
// var r struct {
// hasAccess string `db:"has_database_privilege" json:"has_database_privilege"`
// }
//err := socialHarvest.Database.Postgres.Get(&r, "SELECT * FROM has_database_privilege("+socialHarvest.Config.Database.User+", "+socialHarvest.Config.Database.Database+", 'connect')")
//res.Data["r"] = r
//res.Data["err"] = err
res.Data["hasAccess"] = socialHarvest.Database.HasAccess()
}
if socialHarvest.Database.InfluxDB != nil {
res.Data["type"] = "infxludb"
}

res.Data["configuredType"] = socialHarvest.Config.Database.Type

res.Success()
w.WriteJson(res.End())
}

// API: Territory list returns all currently configured territories and their settings
func TerritoryList(w rest.ResponseWriter, r *rest.Request) {
res := setTerritoryLinks("territory:list")
Expand Down Expand Up @@ -286,10 +314,6 @@ func setConfig(original bool) error {

// Continue configuration
socialHarvest.Database = config.NewDatabase(socialHarvest.Config)
// NOTE: A database is optional for Social Harvest (harvested data can be logged for use with Fluentd for example)
if socialHarvest.Database.Postgres != nil {
defer socialHarvest.Database.Postgres.Close()
}
socialHarvest.Schedule = config.NewSchedule(socialHarvest.Config)

// this gets the configuration and the database. TODO: Make database optional
Expand All @@ -315,6 +339,10 @@ func main() {
if cErr != nil {
log.Fatalln("Failed to load the harvester configuration.")
}
// NOTE: A database is optional for Social Harvest (harvested data can be logged for use with Fluentd for example)
if socialHarvest.Database.Postgres != nil {
defer socialHarvest.Database.Postgres.Close()
}

// Debug - do not compile with this
// runtime.SetBlockProfileRate(1)
Expand Down Expand Up @@ -395,6 +423,7 @@ func main() {
&rest.Route{"GET", "/config/read", ShowSocialHarvestConfig},
&rest.Route{"POST", "/config/write", WriteSocialHarvestConfig},
&rest.Route{"GET", "/config/reload", ReloadSocialHarvestConfig},
&rest.Route{"GET", "/database/info", DatabaseInfo},
&rest.Route{"GET", "/territory/list", TerritoryList},
)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion scripts/postgresql/shared_links.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ CREATE TABLE "shared_links" (
"contributor_county" varchar(75) COLLATE "default"
)
WITH (OIDS=FALSE);
ALTER TABLE "shared_links" OWNER TO "upper";

-- ----------------------------
-- Primary key structure for table shared_links
Expand Down

0 comments on commit 49db876

Please sign in to comment.