github.com/friesencr/pop/v6@v6.1.6/commands.go (about)

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