mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-11 23:50:04 +01:00
Write log lines to DB.Log output (#195)
This makes it possible to redirect the logs somewhere else, useful if you embed dbmate into your application.
This commit is contained in:
parent
454f93a000
commit
2bac2c7590
6 changed files with 44 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
|
@ -21,6 +22,7 @@ func init() {
|
|||
type Driver struct {
|
||||
migrationsTableName string
|
||||
databaseURL *url.URL
|
||||
log io.Writer
|
||||
}
|
||||
|
||||
// NewDriver initializes the driver
|
||||
|
|
@ -28,6 +30,7 @@ func NewDriver(config dbmate.DriverConfig) dbmate.Driver {
|
|||
return &Driver{
|
||||
migrationsTableName: config.MigrationsTableName,
|
||||
databaseURL: config.DatabaseURL,
|
||||
log: config.Log,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +95,7 @@ func (drv *Driver) quoteIdentifier(str string) string {
|
|||
// CreateDatabase creates the specified database
|
||||
func (drv *Driver) CreateDatabase() error {
|
||||
name := dbutil.DatabaseName(drv.databaseURL)
|
||||
fmt.Printf("Creating: %s\n", name)
|
||||
fmt.Fprintf(drv.log, "Creating: %s\n", name)
|
||||
|
||||
db, err := drv.openRootDB()
|
||||
if err != nil {
|
||||
|
|
@ -109,7 +112,7 @@ func (drv *Driver) CreateDatabase() error {
|
|||
// DropDatabase drops the specified database (if it exists)
|
||||
func (drv *Driver) DropDatabase() error {
|
||||
name := dbutil.DatabaseName(drv.databaseURL)
|
||||
fmt.Printf("Dropping: %s\n", name)
|
||||
fmt.Fprintf(drv.log, "Dropping: %s\n", name)
|
||||
|
||||
db, err := drv.openRootDB()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue