MCPcopy Create free account
hub / github.com/bytebase/bytebase / findDisjointUniqueKey

Function findDisjointUniqueKey

backend/plugin/parser/pg/restore.go:229–253  ·  view source on GitHub ↗
(table *model.TableMetadata, fields []string)

Source from the content-addressed store, hash-verified

227}
228
229func findDisjointUniqueKey(table *model.TableMetadata, fields []string) (string, error) {
230 columnMap := make(map[string]bool)
231 for _, field := range fields {
232 columnMap[field] = true
233 }
234 pk := table.GetPrimaryKey()
235 if pk != nil {
236 if disjoint(pk.GetProto().Expressions, columnMap) {
237 return pk.GetProto().Name, nil
238 }
239 }
240 for _, index := range table.GetProto().Indexes {
241 if index.Primary {
242 continue
243 }
244 if !index.Unique {
245 continue
246 }
247 if disjoint(index.Expressions, columnMap) {
248 return index.Name, nil
249 }
250 }
251
252 return "", errors.Errorf("no disjoint unique key found for table")
253}
254
255func extractStatement(statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error) {
256 if backupItem == nil {

Callers 1

doGenerateFunction · 0.85

Calls 4

GetPrimaryKeyMethod · 0.80
ErrorfMethod · 0.80
disjointFunction · 0.70
GetProtoMethod · 0.45

Tested by

no test coverage detected