2017-11-01 14:40:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2017-11-01 15:17:01 +00:00
|
|
|
"fmt"
|
|
|
|
|
2017-11-09 19:34:58 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/cmd"
|
2017-11-06 18:53:43 +00:00
|
|
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
2017-11-01 14:40:04 +00:00
|
|
|
do "gopkg.in/godo.v2"
|
|
|
|
)
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
func parseEnvironment(context *do.Context) string {
|
|
|
|
environment := context.Args.MayString("", "environment", "env", "e")
|
|
|
|
if environment == "" {
|
|
|
|
log.Fatalln("--environment required")
|
2017-11-01 15:17:01 +00:00
|
|
|
}
|
2017-11-02 22:37:27 +00:00
|
|
|
return environment
|
2017-11-01 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 14:40:04 +00:00
|
|
|
func tasks(p *do.Project) {
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
p.Task("run", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
2017-11-06 17:40:52 +00:00
|
|
|
context.Start(`go run main.go --environment={{.environment}}`,
|
|
|
|
do.M{"environment": environment, "$in": "cmd/run"})
|
2017-11-01 15:17:01 +00:00
|
|
|
})
|
|
|
|
|
2017-12-20 20:06:22 +00:00
|
|
|
p.Task("vulcanizeDb", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
|
|
|
context.Start(`go run main.go --environment={{.environment}}`,
|
|
|
|
do.M{"environment": environment, "$in": "cmd/vulcanize_db"})
|
|
|
|
})
|
|
|
|
|
2017-11-06 20:36:12 +00:00
|
|
|
p.Task("populateBlocks", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
|
|
|
startingNumber := context.Args.MayInt(-1, "starting-number")
|
|
|
|
if startingNumber < 0 {
|
|
|
|
log.Fatalln("--starting-number required")
|
|
|
|
}
|
|
|
|
context.Start(`go run main.go --environment={{.environment}} --starting-number={{.startingNumber}}`,
|
|
|
|
do.M{"environment": environment, "startingNumber": startingNumber, "$in": "cmd/populate_blocks"})
|
|
|
|
})
|
|
|
|
|
2017-12-11 21:08:00 +00:00
|
|
|
p.Task("getLogs", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
|
|
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
|
|
|
if contractHash == "" {
|
|
|
|
log.Fatalln("--contract-hash required")
|
|
|
|
}
|
2017-12-22 17:42:35 +00:00
|
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}}`,
|
2017-12-11 21:08:00 +00:00
|
|
|
do.M{
|
|
|
|
"environment": environment,
|
|
|
|
"contractHash": contractHash,
|
|
|
|
"$in": "cmd/get_logs",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-13 16:11:27 +00:00
|
|
|
p.Task("watchContract", nil, func(context *do.Context) {
|
2017-11-09 19:59:12 +00:00
|
|
|
environment := parseEnvironment(context)
|
|
|
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
2017-12-04 21:12:27 +00:00
|
|
|
abiFilepath := context.Args.MayString("", "abi-filepath", "a")
|
2017-11-09 19:59:12 +00:00
|
|
|
if contractHash == "" {
|
|
|
|
log.Fatalln("--contract-hash required")
|
|
|
|
}
|
2017-12-04 21:12:27 +00:00
|
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}}`,
|
|
|
|
do.M{
|
|
|
|
"environment": environment,
|
|
|
|
"contractHash": contractHash,
|
|
|
|
"abiFilepath": abiFilepath,
|
2017-12-13 16:51:11 +00:00
|
|
|
"$in": "cmd/watch_contract",
|
2017-12-04 21:12:27 +00:00
|
|
|
})
|
2017-11-09 19:59:12 +00:00
|
|
|
})
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
p.Task("migrate", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
2017-11-09 19:34:58 +00:00
|
|
|
cfg := cmd.LoadConfig(environment)
|
2017-11-02 22:37:27 +00:00
|
|
|
connectString := config.DbConnectionString(cfg.Database)
|
2017-11-06 19:11:56 +00:00
|
|
|
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations up", connectString)
|
|
|
|
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > ./db/schema.sql", cfg.Database.Name)
|
2017-11-02 22:37:27 +00:00
|
|
|
context.Bash(migrate)
|
|
|
|
context.Bash(dumpSchema)
|
2017-11-01 15:17:01 +00:00
|
|
|
})
|
|
|
|
|
2017-11-02 22:37:27 +00:00
|
|
|
p.Task("rollback", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
2017-11-09 19:34:58 +00:00
|
|
|
cfg := cmd.LoadConfig(environment)
|
2017-11-02 22:37:27 +00:00
|
|
|
connectString := config.DbConnectionString(cfg.Database)
|
2017-11-06 19:11:56 +00:00
|
|
|
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations down 1", connectString)
|
|
|
|
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > ./db/schema.sql", cfg.Database.Name)
|
2017-11-02 22:37:27 +00:00
|
|
|
context.Bash(migrate)
|
|
|
|
context.Bash(dumpSchema)
|
2017-11-01 14:40:04 +00:00
|
|
|
})
|
|
|
|
|
2017-11-13 15:58:36 +00:00
|
|
|
p.Task("showContractSummary", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
|
|
|
contractHash := context.Args.MayString("", "contract-hash", "c")
|
2017-12-07 15:58:06 +00:00
|
|
|
blockNumber := context.Args.MayInt(-1, "block-number", "b")
|
2017-11-13 15:58:36 +00:00
|
|
|
if contractHash == "" {
|
|
|
|
log.Fatalln("--contract-hash required")
|
|
|
|
}
|
2017-12-07 15:58:06 +00:00
|
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --block-number={{.blockNumber}}`,
|
|
|
|
do.M{"environment": environment,
|
|
|
|
"contractHash": contractHash,
|
|
|
|
"blockNumber": blockNumber,
|
|
|
|
"$in": "cmd/show_contract_summary"})
|
2017-11-13 15:58:36 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
do.Godo(tasks)
|
|
|
|
}
|