Skip to content

Commit

Permalink
preserve user specific URL options while 'db create' and 'db drop'.
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Mar 5, 2018
1 parent 91a763b commit 548d273
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (m *mysql) URL() string {

func (m *mysql) urlWithoutDb() string {
c := m.ConnectionDetails
if m.ConnectionDetails.URL != "" {
// respect user's own URL definition (with options).
url := strings.TrimPrefix(m.ConnectionDetails.URL, "mysql://")
return strings.Replace(url, "/"+c.Database+"?", "/?", 1)
}
s := "%s:%s@(%s:%s)/?parseTime=true&multiStatements=true&readTimeout=1s"
return fmt.Sprintf(s, c.User, c.Password, c.Host, c.Port)
}
Expand Down
21 changes: 21 additions & 0 deletions mysql_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pop

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_MySQL_URL(t *testing.T) {
r := require.New(t)

cd := &ConnectionDetails{
URL: "mysql://dbase:dbase@(dbase:dbase)/dbase?dbase=dbase",
}
err := cd.Finalize()
r.NoError(err)

m := &mysql{ConnectionDetails: cd}
r.Equal("dbase:dbase@(dbase:dbase)/dbase?dbase=dbase", m.URL())
r.Equal("dbase:dbase@(dbase:dbase)/?dbase=dbase", m.urlWithoutDb())
}

0 comments on commit 548d273

Please sign in to comment.