-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
commands.go
37 lines (29 loc) · 847 Bytes
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package pop
import (
"fmt"
"github.com/gobuffalo/pop/v6/logging"
)
// CreateDB creates a database, given a connection definition
func CreateDB(c *Connection) error {
deets := c.Dialect.Details()
if deets.Database == "" {
return nil
}
log(logging.Info, fmt.Sprintf("create %s (%s)", deets.Database, c.URL()))
if err := c.Dialect.CreateDB(); err != nil {
return fmt.Errorf("couldn't create database %s: %w", deets.Database, err)
}
return nil
}
// DropDB drops an existing database, given a connection definition
func DropDB(c *Connection) error {
deets := c.Dialect.Details()
if deets.Database == "" {
return nil
}
log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL()))
if err := c.Dialect.DropDB(); err != nil {
return fmt.Errorf("couldn't drop database %s: %w", deets.Database, err)
}
return nil
}