diff --git a/bdb/interface_test.go b/bdb/interface_test.go index 73cd4f5..353a46b 100644 --- a/bdb/interface_test.go +++ b/bdb/interface_test.go @@ -6,14 +6,14 @@ import ( "github.com/vattle/sqlboiler/strmangle" ) -type mockDriver struct{} +type testMockDriver struct{} -func (m mockDriver) TranslateColumnType(c Column) Column { return c } -func (m mockDriver) UseLastInsertID() bool { return false } -func (m mockDriver) Open() error { return nil } -func (m mockDriver) Close() {} +func (m testMockDriver) TranslateColumnType(c Column) Column { return c } +func (m testMockDriver) UseLastInsertID() bool { return false } +func (m testMockDriver) Open() error { return nil } +func (m testMockDriver) Close() {} -func (m mockDriver) TableNames(whitelist, blacklist []string) ([]string, error) { +func (m testMockDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error) { if len(whitelist) > 0 { return whitelist, nil } @@ -22,7 +22,7 @@ func (m mockDriver) TableNames(whitelist, blacklist []string) ([]string, error) } // Columns returns a list of mock columns -func (m mockDriver) Columns(tableName string) ([]Column, error) { +func (m testMockDriver) Columns(schema, tableName string) ([]Column, error) { return map[string][]Column{ "pilots": { {Name: "id", Type: "int", DBType: "integer"}, @@ -64,7 +64,7 @@ func (m mockDriver) Columns(tableName string) ([]Column, error) { } // ForeignKeyInfo returns a list of mock foreignkeys -func (m mockDriver) ForeignKeyInfo(tableName string) ([]ForeignKey, error) { +func (m testMockDriver) ForeignKeyInfo(schema, tableName string) ([]ForeignKey, error) { return map[string][]ForeignKey{ "jets": { {Table: "jets", Name: "jets_pilot_id_fk", Column: "pilot_id", ForeignTable: "pilots", ForeignColumn: "id", ForeignColumnUnique: true}, @@ -84,7 +84,7 @@ func (m mockDriver) ForeignKeyInfo(tableName string) ([]ForeignKey, error) { } // PrimaryKeyInfo returns mock primary key info for the passed in table name -func (m mockDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) { +func (m testMockDriver) PrimaryKeyInfo(schema, tableName string) (*PrimaryKey, error) { return map[string]*PrimaryKey{ "pilots": {Name: "pilot_id_pkey", Columns: []string{"id"}}, "airports": {Name: "airport_id_pkey", Columns: []string{"id"}}, @@ -99,7 +99,7 @@ func (m mockDriver) PrimaryKeyInfo(tableName string) (*PrimaryKey, error) { func TestTables(t *testing.T) { t.Parallel() - tables, err := Tables(mockDriver{}, nil, nil) + tables, err := Tables(testMockDriver{}, "public", nil, nil) if err != nil { t.Error(err) } diff --git a/strmangle/strmangle.go b/strmangle/strmangle.go index 5bda771..3c1fa87 100644 --- a/strmangle/strmangle.go +++ b/strmangle/strmangle.go @@ -39,7 +39,7 @@ func init() { // for Postgres: "schema_name"."table_name", versus // simply "table_name" for MySQL (because it does not support real schemas) func SchemaTable(driver string, schema string, table string) string { - if driver == "postgres" { + if driver == "postgres" && schema != "public" { return fmt.Sprintf(`"%s"."%s"`, schema, table) } diff --git a/text_helpers_test.go b/text_helpers_test.go index a85a4e5..5a09e8a 100644 --- a/text_helpers_test.go +++ b/text_helpers_test.go @@ -12,7 +12,7 @@ import ( func TestTextsFromForeignKey(t *testing.T) { t.Parallel() - tables, err := bdb.Tables(&drivers.MockDriver{}, nil, nil) + tables, err := bdb.Tables(&drivers.MockDriver{}, "public", nil, nil) if err != nil { t.Fatal(err) } @@ -81,7 +81,7 @@ func TestTextsFromForeignKey(t *testing.T) { func TestTextsFromOneToOneRelationship(t *testing.T) { t.Parallel() - tables, err := bdb.Tables(&drivers.MockDriver{}, nil, nil) + tables, err := bdb.Tables(&drivers.MockDriver{}, "public", nil, nil) if err != nil { t.Fatal(err) } @@ -130,7 +130,7 @@ func TestTextsFromOneToOneRelationship(t *testing.T) { func TestTextsFromRelationship(t *testing.T) { t.Parallel() - tables, err := bdb.Tables(&drivers.MockDriver{}, nil, nil) + tables, err := bdb.Tables(&drivers.MockDriver{}, "public", nil, nil) if err != nil { t.Fatal(err) }