Add Up command to create database and migrate

This commit is contained in:
Adrian Macneil 2015-11-27 10:34:42 -08:00
parent 1c4cf2c122
commit 164ec81370
5 changed files with 125 additions and 31 deletions

View file

@ -14,6 +14,32 @@ import (
"time"
)
// UpCommand creates the database (if necessary) and runs migrations
func UpCommand(ctx *cli.Context) error {
u, err := GetDatabaseURL(ctx)
if err != nil {
return err
}
drv, err := driver.Get(u.Scheme)
if err != nil {
return err
}
// create database if it does not already exist
// skip this step if we cannot determine status
// (e.g. user does not have list database permission)
exists, err := drv.DatabaseExists(u)
if err == nil && !exists {
if err := drv.CreateDatabase(u); err != nil {
return err
}
}
// migrate
return MigrateCommand(ctx)
}
// CreateCommand creates the current database
func CreateCommand(ctx *cli.Context) error {
u, err := GetDatabaseURL(ctx)