mirror of
https://github.com/ent/ent.git
synced 2026-05-04 00:20:58 +03:00
dialect/sql/schema: skip default value parsing on pg functions (#951)
Closes #934
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user