Skip to content

Commit 633326f

Browse files
committed
Merge branch 'development'
2 parents 6c1d2c2 + 1c19a1a commit 633326f

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

dialect_cockroach.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
const nameCockroach = "cockroach"
2424
const portCockroach = "26257"
2525

26-
const selectTablesQueryCockroach = "select table_name from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' and table_catalog = ?"
27-
const selectTablesQueryCockroachV1 = "select table_name from information_schema.tables where table_schema = ?"
26+
const selectTablesQueryCockroach = "select table_name from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' and table_name <> ? and table_catalog = ?"
27+
const selectTablesQueryCockroachV1 = "select table_name from information_schema.tables where table_name <> ? and table_schema = ?"
2828

2929
func init() {
3030
AvailableDialects = append(AvailableDialects, nameCockroach)
@@ -209,7 +209,7 @@ func (p *cockroach) TruncateAll(tx *Connection) error {
209209
tableQuery := p.tablesQuery()
210210

211211
var tables []table
212-
if err := tx.RawQuery(tableQuery, tx.Dialect.Details().Database).All(&tables); err != nil {
212+
if err := tx.RawQuery(tableQuery, tx.MigrationTableName(), tx.Dialect.Details().Database).All(&tables); err != nil {
213213
return err
214214
}
215215

dialect_common.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ func (commonDialect) Lock(fn func() error) error {
3131
}
3232

3333
func (commonDialect) Quote(key string) string {
34-
return fmt.Sprintf(`"%s"`, key)
34+
parts := strings.Split(key, ".")
35+
36+
for i, part := range parts {
37+
part = strings.Trim(part, `"`)
38+
part = strings.TrimSpace(part)
39+
40+
parts[i] = fmt.Sprintf(`"%v"`, part)
41+
}
42+
43+
return strings.Join(parts, ".")
3544
}
3645

3746
func genericCreate(s store, model *Model, cols columns.Columns, quoter quotable) error {

dialect_postgresql_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ func Test_PostgreSQL_Connection_String_Failure(t *testing.T) {
7979
r.Error(err)
8080
r.Equal("postgres", cd.Dialect)
8181
}
82+
83+
func Test_PostgreSQL_Quotable(t *testing.T) {
84+
r := require.New(t)
85+
p := postgresql{}
86+
87+
r.Equal(`"table_name"`, p.Quote("table_name"))
88+
r.Equal(`"schema"."table_name"`, p.Quote("schema.table_name"))
89+
r.Equal(`"schema"."table name"`, p.Quote(`"schema"."table name"`))
90+
}

genny/fizz/ctable/create_table_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ func Test_New(t *testing.T) {
2626
},
2727
`create_table("widgets") {
2828
t.Timestamps()
29+
}`,
30+
},
31+
{
32+
&Options{
33+
TableName: "widget",
34+
Name: "create_widgets",
35+
ForceDefaultTimestamps: true,
36+
},
37+
`create_table("widgets") {
38+
t.Timestamps()
2939
}`,
3040
},
3141
{

genny/fizz/ctable/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ func (opts *Options) Validate() error {
3939
if len(opts.TableName) == 0 {
4040
return errors.New("you must set a name for your table")
4141
}
42+
opts.TableName = name.New(opts.TableName).Tableize().String()
4243
if len(opts.Path) == 0 {
4344
opts.Path = "migrations"
4445
}
4546
if len(opts.Name) == 0 {
4647
timestamp := nowFunc().UTC().Format("20060102150405")
47-
opts.Name = fmt.Sprintf("%s_create_%s", timestamp, name.New(opts.TableName).Tableize())
48+
opts.Name = fmt.Sprintf("%s_create_%s", timestamp, opts.TableName)
4849
}
4950
if len(opts.Type) == 0 {
5051
opts.Type = "fizz"

0 commit comments

Comments
 (0)