Skip to content

Commit c3bfab8

Browse files
sql/ydb: fixed index introspection
1 parent d43ce93 commit c3bfab8

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

sql/ydb/diff.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,26 @@ func (d *diff) defaultChanged(from *schema.Column, to *schema.Column) bool {
129129

130130
// IndexAttrChanged reports if the index attributes were changed.
131131
func (*diff) IndexAttrChanged(from, to []schema.Attr) bool {
132-
var fromA, toA IndexAttributes
133-
fromHas, toHas := sqlx.Has(from, &fromA), sqlx.Has(to, &toA)
134-
if fromHas != toHas {
132+
var fromAttrs, toAttrs IndexAttributes
133+
hasFrom, hasTo := sqlx.Has(from, &fromAttrs), sqlx.Has(to, &toAttrs)
134+
135+
if hasFrom != hasTo {
135136
return true
136137
}
137-
if !fromHas {
138+
if !hasFrom {
138139
return false
139140
}
140141

141-
if fromA.Async != toA.Async {
142+
if fromAttrs.Async != toAttrs.Async {
142143
return true
143144
}
144145

145-
if len(fromA.CoverColumns) != len(toA.CoverColumns) {
146+
if len(fromAttrs.CoverColumns) != len(toAttrs.CoverColumns) {
146147
return true
147148
}
148149

149-
for i := range fromA.CoverColumns {
150-
if fromA.CoverColumns[i].Name != toA.CoverColumns[i].Name {
150+
for i := range fromAttrs.CoverColumns {
151+
if fromAttrs.CoverColumns[i].Name != toAttrs.CoverColumns[i].Name {
151152
return true
152153
}
153154
}

sql/ydb/inspect.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ func (i *inspect) indexes(
308308
})
309309
}
310310

311+
indexAttrs := &IndexAttributes{
312+
Async: idx.Type == options.GlobalAsyncIndex(),
313+
}
314+
for _, dataCol := range idx.DataColumns {
315+
column, ok := table.Column(dataCol)
316+
if !ok {
317+
return fmt.Errorf("ydb: cover column %q not found in table %q", dataCol, table.Name)
318+
}
319+
indexAttrs.CoverColumns = append(indexAttrs.CoverColumns, column)
320+
}
321+
if indexAttrs.Async || len(indexAttrs.CoverColumns) > 0 {
322+
atlasIdx.Attrs = append(atlasIdx.Attrs, indexAttrs)
323+
}
324+
311325
table.AddIndexes(atlasIdx)
312326
}
313327

0 commit comments

Comments
 (0)