aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--golang/Gopkg.lock8
-rw-r--r--golang/cmd/fatcatd/reinit.go42
-rw-r--r--golang/cmd/fatcatd/root.go2
-rw-r--r--golang/fatcatd.toml1
-rw-r--r--golang/sql/fatcat-schema.sql (renamed from golang/fatcat-schema.sql)0
5 files changed, 51 insertions, 2 deletions
diff --git a/golang/Gopkg.lock b/golang/Gopkg.lock
index 624973cf..eedeab82 100644
--- a/golang/Gopkg.lock
+++ b/golang/Gopkg.lock
@@ -159,6 +159,12 @@
version = "v6.11.2"
[[projects]]
+ name = "github.com/gobuffalo/packr"
+ packages = ["."]
+ revision = "7f4074995d431987caaa35088199f13c44b24440"
+ version = "v1.11.0"
+
+[[projects]]
branch = "master"
name = "github.com/hashicorp/hcl"
packages = [
@@ -366,6 +372,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "6f07904be5d2765e24cd25378e28c8c1c34f6e4205100dc6f8364d0be5eafbf9"
+ inputs-digest = "551e8d9bd6a848cc1a77d0706bb2275d4ff4052d83c7e2a82494ee2ee8821805"
solver-name = "gps-cdcl"
solver-version = 1
diff --git a/golang/cmd/fatcatd/reinit.go b/golang/cmd/fatcatd/reinit.go
new file mode 100644
index 00000000..b7cfa468
--- /dev/null
+++ b/golang/cmd/fatcatd/reinit.go
@@ -0,0 +1,42 @@
+
+package main
+
+import (
+ "github.com/spf13/viper"
+ log "github.com/sirupsen/logrus"
+ "github.com/go-pg/pg"
+ "github.com/spf13/cobra"
+ "github.com/gobuffalo/packr"
+)
+
+var reinitCmd = &cobra.Command{
+ Use: "reinit [options]",
+ Short: "Reset database schema",
+ Run: func(cmd *cobra.Command, args[] string) {
+ main_reinit()
+ },
+}
+
+func main_reinit() {
+
+ box := packr.NewBox("../../sql")
+ sql_schema, err := box.MustString("fatcat-schema.sql")
+ if err != nil {
+ log.Panicf("finding SQL file: {}", err)
+ }
+
+ db_options, err := pg.ParseURL(viper.GetString("db_url"))
+ if err != nil {
+ log.Panicf("parsing DB string: {}", err)
+ }
+ db := pg.Connect(db_options)
+ defer db.Close()
+
+ log.Info("Starting load...")
+ _, err = db.Exec(sql_schema)
+ if err != nil {
+ log.Fatalf("Error loading SQL: {}", err)
+ }
+ log.Info("Success!")
+
+}
diff --git a/golang/cmd/fatcatd/root.go b/golang/cmd/fatcatd/root.go
index b5263b06..12be35b3 100644
--- a/golang/cmd/fatcatd/root.go
+++ b/golang/cmd/fatcatd/root.go
@@ -29,12 +29,12 @@ func init() {
serveCmd.Flags().String("db-url", "postgres://", "database connecion string")
rootCmd.AddCommand(serveCmd)
+ rootCmd.AddCommand(reinitCmd)
}
func initConfig() {
viper.SetDefault("port", 9411)
- viper.SetDefault("db_url", "postgres://bnewbold@localhost/fatcat")
viper.SetEnvPrefix("FATCAT")
viper.AutomaticEnv()
diff --git a/golang/fatcatd.toml b/golang/fatcatd.toml
index bd839b19..56316061 100644
--- a/golang/fatcatd.toml
+++ b/golang/fatcatd.toml
@@ -1 +1,2 @@
verbose = false
+db_url = "postgres://fatcat:tactaf@localhost/fatcat"
diff --git a/golang/fatcat-schema.sql b/golang/sql/fatcat-schema.sql
index f5983371..f5983371 100644
--- a/golang/fatcat-schema.sql
+++ b/golang/sql/fatcat-schema.sql