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-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-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
|
|
|
if abiFilepath == "" {
|
|
|
|
log.Fatalln("--abi-filepath required")
|
|
|
|
}
|
|
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}}`,
|
|
|
|
do.M{
|
|
|
|
"environment": environment,
|
|
|
|
"contractHash": contractHash,
|
|
|
|
"abiFilepath": abiFilepath,
|
|
|
|
"$in": "cmd/subscribe_contract",
|
|
|
|
})
|
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")
|
|
|
|
if contractHash == "" {
|
|
|
|
log.Fatalln("--contract-hash required")
|
|
|
|
}
|
|
|
|
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}}`,
|
|
|
|
do.M{"environment": environment, "contractHash": contractHash, "$in": "cmd/show_contract_summary"})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
do.Godo(tasks)
|
|
|
|
}
|