mi-v1/cmd/mi-init/main.go

58 lines
983 B
Go
Raw Normal View History

2020-01-11 21:06:44 +00:00
package main
import (
"flag"
"log"
"github.com/facebookgo/flagenv"
"github.com/hashicorp/go-multierror"
_ "github.com/joho/godotenv/autoload"
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
"within.website/mi/rethink"
)
var (
rethinkDBURL = flag.String("rethinkdb-url", "rethinkdb2://admin@127.0.0.1:28015/mi", "RethinkDB URL")
)
func main() {
flagenv.Parse()
flag.Parse()
session, err := rethink.GetSession(*rethinkDBURL)
if err != nil {
log.Fatal(err)
}
err = r.DB("mi").Info().Exec(session)
if err == nil {
return
}
if err := r.DBCreate("mi").Exec(session); err != nil {
log.Fatal(err)
}
tables := []string{
"mastodon",
"blogposts",
"reddit_comments",
"reddit_posts",
"twitter",
}
var result error
for _, tbl := range tables {
if err := r.DB("mi").TableCreate(tbl).Exec(session); err != nil {
result = multierror.Append(result, err)
2020-01-11 21:15:12 +00:00
} else {
log.Printf("created table %s", tbl)
2020-01-11 21:06:44 +00:00
}
}
if result != nil {
log.Fatal(result)
}
}