Fix created_at default val in v4 migration for SQLite

This previously used a default timestamp value which caused the
migration to fail for SQLite databases.
This commit is contained in:
Matt Baer 2020-03-03 11:26:23 -06:00
parent 793380c1d9
commit 5b2612af54
2 changed files with 10 additions and 1 deletions

View file

@ -139,6 +139,15 @@ func (c *Column) SetDefault(value string) *Column {
return c
}
func (c *Column) SetDefaultCurrentTimestamp() *Column {
def := "NOW()"
if c.Dialect == DialectSQLite {
def = "CURRENT_TIMESTAMP"
}
c.Default = OptionalString{Set: true, Value: def}
return c
}
func (c *Column) SetType(t ColumnType) *Column {
c.Type = t
return c

View file

@ -29,7 +29,7 @@ func oauth(db *datastore) error {
SetIfNotExists(true).
Column(dialect.Column("state", wf_db.ColumnTypeVarChar, wf_db.OptionalInt{Set: true, Value: 255})).
Column(dialect.Column("used", wf_db.ColumnTypeBool, wf_db.UnsetSize)).
Column(dialect.Column("created_at", wf_db.ColumnTypeDateTime, wf_db.UnsetSize).SetDefault("NOW()")).
Column(dialect.Column("created_at", wf_db.ColumnTypeDateTime, wf_db.UnsetSize).SetDefaultCurrentTimestamp()).
UniqueConstraint("state").
ToSQL()
if err != nil {