dialect/sql/schema: support DESC indexes using atlasgo.io

This commit is contained in:
Ariel Mashraki
2022-01-31 13:22:26 +02:00
committed by Ariel Mashraki
parent 94499bd141
commit 51663407cf
6 changed files with 37 additions and 3 deletions

View File

@@ -468,6 +468,10 @@ func (m *Migrate) aIndexes(b atBuilder, t1 *Table, t2 *schema.Table) error {
if err := b.atIndex(idx1, t2, idx2); err != nil {
return err
}
desc := descIndexes(idx1)
for _, p := range idx2.Parts {
p.Desc = desc[p.C.Name]
}
t2.AddIndexes(idx2)
}
return nil
@@ -493,3 +497,20 @@ func setAtChecks(t1 *Table, t2 *schema.Table) {
}
}
}
// descIndexes returns a map holding the DESC mapping if exist.
func descIndexes(idx *Index) map[string]bool {
descs := make(map[string]bool)
if idx.Annotation == nil {
return descs
}
// If DESC (without a column) was defined on the
// annotation, map it to the single column index.
if idx.Annotation.Desc && len(idx.Columns) == 1 {
descs[idx.Columns[0].Name] = idx.Annotation.Desc
}
for column, desc := range idx.Annotation.DescColumns {
descs[column] = desc
}
return descs
}