ipld-eth-server/Gododir/main.go

53 lines
1.4 KiB
Go
Raw Normal View History

2017-11-01 14:40:04 +00:00
package main
import (
"log"
"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-02 22:37:27 +00:00
return environment
}
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)
context.Start(`go run main.go --environment={{.environment}}`,
do.M{"environment": environment, "$in": "cmd/run"})
})
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)
migrate := fmt.Sprintf("migrate -database '%s' -path ./migrations up", connectString)
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Database.Name)
context.Bash(migrate)
context.Bash(dumpSchema)
})
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)
migrate := fmt.Sprintf("migrate -database '%s' -path ./migrations down 1", connectString)
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Database.Name)
context.Bash(migrate)
context.Bash(dumpSchema)
2017-11-01 14:40:04 +00:00
})
}
func main() {
do.Godo(tasks)
}