dialect/sql/schema: support setting default value expressions on id fields (#3089)

This commit is contained in:
Ariel Mashraki
2022-11-13 18:55:04 +02:00
committed by GitHub
parent 53bdc325c0
commit 891fc8fecf
24 changed files with 1839 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ package schema
import (
"context"
"fmt"
"reflect"
"strconv"
"strings"
"unicode"
@@ -769,7 +770,10 @@ func (d *Postgres) atImplicitIndexName(idx *Index, t1 *Table, c1 *Column) bool {
}
func (d *Postgres) atIncrementC(t *schema.Table, c *schema.Column) {
if _, ok := c.Type.Type.(*postgres.SerialType); ok {
// Skip marking this column as an identity in case it is
// serial type or a default was already defined for it.
if _, ok := c.Type.Type.(*postgres.SerialType); ok || c.Default != nil {
t.Attrs = removeAttr(t.Attrs, reflect.TypeOf(&postgres.Identity{}))
return
}
id := &postgres.Identity{}