forked from cerc-io/ipld-eth-server
4c84173bc0
* The command populates up to the highest known block number * The anticipated use case is that the listener will be running in parallel to the populateBlocks command * This will mean that the listener is responsible for picking up new blocks, and the populateBlocks command is reposible for historical blocks * Reformat SQL statements
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"fmt"
|
|
|
|
"github.com/8thlight/vulcanizedb/pkg/config"
|
|
do "gopkg.in/godo.v2"
|
|
)
|
|
|
|
func parseEnvironment(context *do.Context) string {
|
|
environment := context.Args.MayString("", "environment", "env", "e")
|
|
if environment == "" {
|
|
log.Fatalln("--environment required")
|
|
}
|
|
return environment
|
|
}
|
|
|
|
func tasks(p *do.Project) {
|
|
|
|
p.Task("run", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
context.Start(`go run main.go --environment={{.environment}}`,
|
|
do.M{"environment": environment, "$in": "cmd/run"})
|
|
})
|
|
|
|
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"})
|
|
})
|
|
|
|
p.Task("migrate", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
cfg := config.NewConfig(environment)
|
|
connectString := config.DbConnectionString(cfg.Database)
|
|
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)
|
|
context.Bash(migrate)
|
|
context.Bash(dumpSchema)
|
|
})
|
|
|
|
p.Task("rollback", nil, func(context *do.Context) {
|
|
environment := parseEnvironment(context)
|
|
cfg := config.NewConfig(environment)
|
|
connectString := config.DbConnectionString(cfg.Database)
|
|
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)
|
|
context.Bash(migrate)
|
|
context.Bash(dumpSchema)
|
|
})
|
|
|
|
}
|
|
|
|
func main() {
|
|
do.Godo(tasks)
|
|
}
|