2017-11-01 14:40:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2017-11-01 15:17:01 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cfg "github.com/8thlight/vulcanizedb/config"
|
2017-11-01 14:40:04 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/core"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
do "gopkg.in/godo.v2"
|
|
|
|
)
|
|
|
|
|
2017-11-01 15:17:01 +00:00
|
|
|
func parseIpcPath(context *do.Context) string {
|
|
|
|
ipcPath := context.Args.MayString("", "ipc-path", "i")
|
|
|
|
if ipcPath == "" {
|
|
|
|
log.Fatalln("--ipc-path required")
|
|
|
|
}
|
|
|
|
return ipcPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func startBlockchainListener(config cfg.Config, ipcPath string) {
|
2017-11-02 11:41:24 +00:00
|
|
|
blockchain := core.NewGethBlockchain(ipcPath)
|
|
|
|
loggingObserver := core.BlockchainLoggingObserver{}
|
|
|
|
connectString := cfg.DbConnectionString(cfg.Public().Database)
|
|
|
|
db, err := sqlx.Connect("postgres", connectString)
|
2017-11-01 15:17:01 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error connecting to DB: %v\n", err)
|
|
|
|
}
|
2017-11-02 11:41:24 +00:00
|
|
|
dbObserver := (core.BlockchainDBObserver{Db: db})
|
|
|
|
listener := core.NewBlockchainListener(blockchain, []core.BlockchainObserver{
|
|
|
|
loggingObserver,
|
|
|
|
dbObserver,
|
|
|
|
})
|
|
|
|
listener.Start()
|
2017-11-01 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 14:40:04 +00:00
|
|
|
func tasks(p *do.Project) {
|
|
|
|
|
2017-11-01 15:17:01 +00:00
|
|
|
p.Task("runPublic", nil, func(context *do.Context) {
|
|
|
|
startBlockchainListener(cfg.Public(), parseIpcPath(context))
|
|
|
|
})
|
|
|
|
|
|
|
|
p.Task("runPrivate", nil, func(context *do.Context) {
|
|
|
|
startBlockchainListener(cfg.Private(), parseIpcPath(context))
|
|
|
|
})
|
|
|
|
|
|
|
|
p.Task("migratePublic", nil, func(context *do.Context) {
|
|
|
|
connectString := cfg.DbConnectionString(cfg.Public().Database)
|
|
|
|
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations up", connectString))
|
|
|
|
context.Bash(fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Public().Database.Name))
|
|
|
|
})
|
|
|
|
|
|
|
|
p.Task("migratePrivate", nil, func(context *do.Context) {
|
|
|
|
connectString := cfg.DbConnectionString(cfg.Private().Database)
|
|
|
|
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations up", connectString))
|
|
|
|
context.Bash(fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Private().Database.Name))
|
|
|
|
})
|
|
|
|
|
|
|
|
p.Task("rollbackPublic", nil, func(context *do.Context) {
|
|
|
|
connectString := cfg.DbConnectionString(cfg.Public().Database)
|
|
|
|
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations down 1", connectString))
|
|
|
|
context.Bash("pg_dump -O -s vulcanize_public > migrations/schema.sql")
|
|
|
|
})
|
|
|
|
|
|
|
|
p.Task("rollbackPrivate", nil, func(context *do.Context) {
|
|
|
|
connectString := cfg.DbConnectionString(cfg.Private().Database)
|
|
|
|
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations down 1", connectString))
|
|
|
|
context.Bash("pg_dump -O -s vulcanize_private > migrations/schema.sql")
|
2017-11-01 14:40:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
do.Godo(tasks)
|
|
|
|
}
|