59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
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 {
|
|
if err := r.DBCreate("mi").Exec(session); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
tables := []string{
|
|
"mastodon",
|
|
"blogposts",
|
|
"reddit_comments",
|
|
"reddit_posts",
|
|
"tweets",
|
|
"switches",
|
|
}
|
|
|
|
var result error
|
|
|
|
for _, tbl := range tables {
|
|
if err := r.DB("mi").Table(tbl).Info().Exec(session); err != nil {
|
|
if err := r.DB("mi").TableCreate(tbl).Exec(session); err != nil {
|
|
result = multierror.Append(result, err)
|
|
} else {
|
|
log.Printf("created table %s", tbl)
|
|
}
|
|
}
|
|
}
|
|
|
|
if result != nil {
|
|
log.Fatal(result)
|
|
}
|
|
}
|