Skip to content

Commit

Permalink
Fix a case with timestamps
Browse files Browse the repository at this point in the history
Timestamp columns provided manually but same as default definition must
use the Timestamps() macro instead of their full definition.
  • Loading branch information
stanislas-m committed Aug 24, 2019
1 parent aecdf24 commit eea01a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t *Table) Column(name string, colType string, options Options) error {
} else {
t.Columns = append(t.Columns, c)
}
if (name == "created_at" || name == "updated_at") && colType != "time" {
if (name == "created_at" || name == "updated_at") && colType != "timestamp" {
// timestamp macro only works for time type
t.useTimestampMacro = false
}
Expand Down
16 changes: 16 additions & 0 deletions tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ func Test_Table_StringerAutoDisableTimestamps(t *testing.T) {
r.NoError(table.Column("created_at", "int", nil))

r.Equal(expected, table.String())

// timestamp columns provided but same as default
expected =
`create_table("users") {
t.Column("name", "string")
t.Timestamps()
}`

table = fizz.NewTable("users", map[string]interface{}{
"timestamps": true,
})
r.NoError(table.Column("name", "string", nil))
r.NoError(table.Column("created_at", "timestamp", nil))
r.NoError(table.Column("updated_at", "timestamp", nil))

r.Equal(expected, table.String())
}

func Test_Table_StringerIndex(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fizz

// Version gives the current fizz version.
const Version = "v1.9.4"
const Version = "v1.9.5"

0 comments on commit eea01a8

Please sign in to comment.