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

Function tidbReorderColumn

backend/plugin/schema/tidb/walk_through.go:770–809  ·  view source on GitHub ↗

tidbReorderColumn reorders the columns for new column and returns the new column position.

(t *model.TableMetadata, position *tidbast.ColumnPosition)

Source from the content-addressed store, hash-verified

768
769// tidbReorderColumn reorders the columns for new column and returns the new column position.
770func tidbReorderColumn(t *model.TableMetadata, position *tidbast.ColumnPosition) (int, *storepb.Advice) {
771 switch position.Tp {
772 case tidbast.ColumnPositionNone:
773 return len(t.GetProto().GetColumns()) + 1, nil
774 case tidbast.ColumnPositionFirst:
775 for _, column := range t.GetProto().GetColumns() {
776 column.Position++
777 }
778 return 1, nil
779 case tidbast.ColumnPositionAfter:
780 columnName := position.RelativeColumn.Name.L
781 column := t.GetColumn(columnName)
782 if column == nil {
783 content := fmt.Sprintf("Column `%s` does not exist in table `%s`", columnName, t.GetProto().Name)
784 return 0, &storepb.Advice{
785 Status: storepb.Advice_ERROR,
786 Code: code.ColumnNotExists.Int32(),
787 Title: content,
788 Content: content,
789 StartPosition: &storepb.Position{Line: 0},
790 }
791 }
792 columnProto := column.GetProto()
793 for _, col := range t.GetProto().GetColumns() {
794 if col.Position > columnProto.Position {
795 col.Position++
796 }
797 }
798 return int(columnProto.Position) + 1, nil
799 default:
800 content := fmt.Sprintf("Unsupported column position type: %d", position.Tp)
801 return 0, &storepb.Advice{
802 Status: storepb.Advice_ERROR,
803 Code: code.Unsupported.Int32(),
804 Title: content,
805 Content: content,
806 StartPosition: &storepb.Position{Line: 0},
807 }
808 }
809}
810
811func tidbDropTable(d *model.DatabaseMetadata, node *tidbast.DropTableStmt) *storepb.Advice {
812 // TODO(rebelice): deal with DROP VIEW statement.

Callers 1

tidbCreateColumnHelperFunction · 0.85

Calls 4

GetColumnsMethod · 0.45
GetProtoMethod · 0.45
GetColumnMethod · 0.45
Int32Method · 0.45

Tested by

no test coverage detected