dialect/sql/schema: skip default value parsing on pg functions (#951)

Closes #934
This commit is contained in:
Ariel Mashraki
2020-11-15 22:55:52 +02:00
committed by GitHub
parent d5b69da9e0
commit 77eaad0df6
2 changed files with 37 additions and 1 deletions

View File

@@ -251,7 +251,7 @@ func (d *Postgres) scanColumn(c *Column, rows *sql.Rows) error {
c.Type = field.TypeUUID
}
switch {
case !defaults.Valid || c.Type == field.TypeTime:
case !defaults.Valid || c.Type == field.TypeTime || seqfunc(defaults.String):
return nil
case strings.Contains(defaults.String, "::"):
parts := strings.Split(defaults.String, "::")
@@ -447,3 +447,13 @@ func (d *Postgres) alterColumns(table string, add, modify, drop []*Column) sql.Q
}
return sql.Queries{b}
}
// seqfunc reports if the given string is a sequence function.
func seqfunc(defaults string) bool {
for _, fn := range [...]string{"currval", "lastval", "setval", "nextval"} {
if strings.HasPrefix(defaults, fn+"(") && strings.HasSuffix(defaults, ")") {
return true
}
}
return false
}