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

Function tidbCreatePrimaryKeyHelper

backend/plugin/schema/tidb/walk_through.go:1358–1388  ·  view source on GitHub ↗
(t *model.TableMetadata, keys []string, tp string)

Source from the content-addressed store, hash-verified

1356}
1357
1358func tidbCreatePrimaryKeyHelper(t *model.TableMetadata, keys []string, tp string) *storepb.Advice {
1359 if t.GetIndex(PrimaryKeyName) != nil {
1360 content := fmt.Sprintf("Primary key exists in table `%s`", t.GetProto().Name)
1361 return &storepb.Advice{
1362 Status: storepb.Advice_ERROR,
1363 Code: code.PrimaryKeyExists.Int32(),
1364 Title: content,
1365 Content: content,
1366 StartPosition: &storepb.Position{Line: 0},
1367 }
1368 }
1369
1370 pk := &storepb.IndexMetadata{
1371 Name: PrimaryKeyName,
1372 Expressions: keys,
1373 Type: tp,
1374 Unique: true,
1375 Primary: true,
1376 Visible: true,
1377 }
1378 if err := t.CreateIndex(pk); err != nil {
1379 return &storepb.Advice{
1380 Status: storepb.Advice_ERROR,
1381 Code: code.IndexExists.Int32(),
1382 Title: err.Error(),
1383 Content: err.Error(),
1384 StartPosition: &storepb.Position{Line: 0},
1385 }
1386 }
1387 return nil
1388}
1389
1390func restoreNode(node tidbast.Node, flag format.RestoreFlags) (string, error) {
1391 var buffer strings.Builder

Callers 2

tidbCreateConstraintFunction · 0.85
tidbCreateColumnHelperFunction · 0.85

Calls 5

CreateIndexMethod · 0.80
GetIndexMethod · 0.45
GetProtoMethod · 0.45
Int32Method · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected