mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 08:00:04 +01:00
Add Up command to create database and migrate
This commit is contained in:
parent
1c4cf2c122
commit
164ec81370
5 changed files with 125 additions and 31 deletions
26
commands.go
26
commands.go
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue