dialect/entsql: add support for index-type annotation

This commit is contained in:
Ariel Mashraki
2022-02-22 13:41:11 +02:00
committed by Ariel Mashraki
parent d80f7cc41a
commit fe2511fc8d
5 changed files with 97 additions and 0 deletions

View File

@@ -951,5 +951,22 @@ func (d *MySQL) atIndex(idx1 *Index, t2 *schema.Table, idx2 *schema.Index) error
}
idx2.AddParts(part)
}
if t, ok := indexType(idx1, dialect.MySQL); ok {
idx2.AddAttrs(&mysql.IndexType{T: t})
}
return nil
}
func indexType(idx *Index, d string) (string, bool) {
ant := idx.Annotation
if ant == nil {
return "", false
}
if ant.Type != "" {
return idx.Annotation.Type, true
}
if ant.Types != nil && ant.Types[d] != "" {
return ant.Types[d], true
}
return "", false
}

View File

@@ -779,5 +779,8 @@ func (d *Postgres) atIndex(idx1 *Index, t2 *schema.Table, idx2 *schema.Index) er
}
idx2.AddParts(&schema.IndexPart{C: c2})
}
if t, ok := indexType(idx1, dialect.Postgres); ok {
idx2.AddAttrs(&postgres.IndexType{T: t})
}
return nil
}