2017-11-01 14:40:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2017-11-01 15:17:01 +00:00
|
|
|
"fmt"
|
|
|
|
|
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-02 22:37:27 +00:00
|
|
|
p.Task("migrate", nil, func(context *do.Context) {
|
|
|
|
environment := parseEnvironment(context)
|
|
|
|
cfg := config.NewConfig(environment)
|
|
|
|
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)
|
|
|
|
cfg := config.NewConfig(environment)
|
|
|
|
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
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
do.Godo(tasks)
|
|
|
|
}
|