Skip to content

Commit 3898c06

Browse files
committed
Merge branch 'development' of github.com:gobuffalo/pop into development
2 parents 7ec576e + 6842d77 commit 3898c06

26 files changed

+841
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center"><img src="logo.png" width="150" height="150"></p>
22

33
<p align="center">
4-
<a href="https://godoc.org/github.com/gobuffalo/pop"><img src="https://godoc.org/github.com/gobuffalo/pop?status.svg" alt="GoDoc" /></a>
5-
<a href="https://dev.azure.com/stanislasmichalak/pop/_build/latest?definitionId=1&branchName=master"><img src="https://dev.azure.com/stanislasmichalak/pop/_apis/build/status/gobuffalo.pop?branchName=master" alt="Build Status" /></a>
4+
<a href="https://pkg.go.dev/github.com/gobuffalo/pop/v5"><img src="https://godoc.org/github.com/gobuffalo/pop?status.svg" alt="GoDoc" /></a>
5+
<a href="https://github.com/gobuffalo/pop/actions?query=workflow%3ATests+branch%3Amaster"><img src="https://github.com/gobuffalo/pop/workflows/Tests/badge.svg" alt="Build Status" /></a>
66
</p>
77

88
# POP

config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ mysql:
3636
port: "3306"
3737
user: "root"
3838
password: "root"
39+
unsafe: true
3940
options:
4041
readTimeout: 5s`)
4142
conns, err := ParseConfig(config)
@@ -48,5 +49,17 @@ mysql:
4849
r.Equal("3306", conns["mysql"].Port)
4950
r.Equal(envy.Get("MYSQL_USER", "root"), conns["mysql"].User)
5051
r.Equal(envy.Get("MYSQL_PASSWORD", "root"), conns["mysql"].Password)
52+
r.True(conns["mysql"].Unsafe)
5153
r.Equal("5s", conns["mysql"].Options["readTimeout"])
5254
}
55+
56+
func Test_ParseConfigUnsafeDefault(t *testing.T) {
57+
// Ensure that the default `unsafe` value is false.
58+
r := require.New(t)
59+
config := strings.NewReader(`
60+
mysql:
61+
dialect: "mysql"`)
62+
conns, err := ParseConfig(config)
63+
r.NoError(err)
64+
r.False(conns["mysql"].Unsafe)
65+
}

connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (c *Connection) Open() error {
9595
return errors.New("invalid connection instance")
9696
}
9797
details := c.Dialect.Details()
98-
driver := details.Dialect
98+
driver := c.Dialect.DefaultDriver()
9999
if details.Driver != "" {
100100
driver = details.Driver
101101
}
@@ -111,6 +111,9 @@ func (c *Connection) Open() error {
111111
if details.ConnMaxLifetime > 0 {
112112
db.SetConnMaxLifetime(details.ConnMaxLifetime)
113113
}
114+
if details.Unsafe {
115+
db = db.Unsafe()
116+
}
114117
c.Store = &dB{db}
115118

116119
if d, ok := c.Dialect.(afterOpenable); ok {

connection_details.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ type ConnectionDetails struct {
4242
IdlePool int
4343
// Defaults to 0 "unlimited". See https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime
4444
ConnMaxLifetime time.Duration
45-
Options map[string]string
45+
// Defaults to `false`. See https://godoc.org/github.com/jmoiron/sqlx#DB.Unsafe
46+
Unsafe bool
47+
Options map[string]string
4648
// Query string encoded options from URL. Example: "sslmode=disable"
4749
RawOptions string
4850
}

connection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Test_Connection_Open_NoDialect(t *testing.T) {
3939
r.Error(err)
4040
}
4141

42-
func Test_Connection_Open_BadDialect(t *testing.T) {
42+
func Test_Connection_Open_BadDriver(t *testing.T) {
4343
r := require.New(t)
4444

4545
cd := &ConnectionDetails{
@@ -48,7 +48,7 @@ func Test_Connection_Open_BadDialect(t *testing.T) {
4848
c, err := NewConnection(cd)
4949
r.NoError(err)
5050

51-
cd.Dialect = "unknown"
51+
cd.Driver = "unknown"
5252
err = c.Open()
5353
r.Error(err)
5454
}

dialect.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type dialect interface {
2828
fizzable
2929
quotable
3030
Name() string
31+
DefaultDriver() string
3132
URL() string
3233
MigrationURL() string
3334
Details() *ConnectionDetails

dialect_cockroach.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"sync"
1212

13-
_ "github.com/cockroachdb/cockroach-go/crdb" // Load CockroachdbQL/postgres Go driver which also loads github.com/lib/pq
1413
"github.com/gobuffalo/fizz"
1514
"github.com/gobuffalo/fizz/translators"
1615
"github.com/gobuffalo/pop/v5/columns"
@@ -57,6 +56,10 @@ func (p *cockroach) Name() string {
5756
return nameCockroach
5857
}
5958

59+
func (p *cockroach) DefaultDriver() string {
60+
return namePostgreSQL
61+
}
62+
6063
func (p *cockroach) Details() *ConnectionDetails {
6164
return p.ConnectionDetails
6265
}

dialect_mysql.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (m *mysql) Name() string {
3939
return nameMySQL
4040
}
4141

42+
func (m *mysql) DefaultDriver() string {
43+
return nameMySQL
44+
}
45+
4246
func (mysql) Quote(key string) string {
4347
return fmt.Sprintf("`%s`", key)
4448
}
@@ -167,7 +171,7 @@ func (m *mysql) LoadSchema(r io.Reader) error {
167171
// TruncateAll truncates all tables for the given connection.
168172
func (m *mysql) TruncateAll(tx *Connection) error {
169173
var stmts []string
170-
err := tx.RawQuery(mysqlTruncate, m.Details().Database).All(&stmts)
174+
err := tx.RawQuery(mysqlTruncate, m.Details().Database, tx.MigrationTableName()).All(&stmts)
171175
if err != nil {
172176
return err
173177
}
@@ -254,4 +258,4 @@ func finalizerMySQL(cd *ConnectionDetails) {
254258
}
255259
}
256260

257-
const mysqlTruncate = "SELECT concat('TRUNCATE TABLE `', TABLE_NAME, '`;') as stmt FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = ? AND table_type <> 'VIEW'"
261+
const mysqlTruncate = "SELECT concat('TRUNCATE TABLE `', TABLE_NAME, '`;') as stmt FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = ? AND table_name <> ? AND table_type <> 'VIEW'"

dialect_postgresql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func (p *postgresql) Name() string {
4343
return namePostgreSQL
4444
}
4545

46+
func (p *postgresql) DefaultDriver() string {
47+
return namePostgreSQL
48+
}
49+
4650
func (p *postgresql) Details() *ConnectionDetails {
4751
return p.ConnectionDetails
4852
}

dialect_sqlite.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (m *sqlite) Name() string {
4545
return nameSQLite3
4646
}
4747

48+
func (m *sqlite) DefaultDriver() string {
49+
return nameSQLite3
50+
}
51+
4852
func (m *sqlite) Details() *ConnectionDetails {
4953
return m.ConnectionDetails
5054
}

0 commit comments

Comments
 (0)