MCPcopy Index your code
hub / github.com/bytebase/bytebase / RenameTable

Method RenameTable

backend/store/model/database.go:578–606  ·  view source on GitHub ↗

RenameTable renames a table in the schema. Returns an error if the old table doesn't exist or new table already exists.

(oldName string, newName string)

Source from the content-addressed store, hash-verified

576// RenameTable renames a table in the schema.
577// Returns an error if the old table doesn't exist or new table already exists.
578func (s *SchemaMetadata) RenameTable(oldName string, newName string) error {
579 if oldName == newName {
580 return nil
581 }
582
583 // Check if old table exists
584 oldTable := s.GetTable(oldName)
585 if oldTable == nil {
586 return errors.Errorf("table %q does not exist in schema %q", oldName, s.proto.Name)
587 }
588
589 // Check if new table already exists
590 if s.GetTable(newName) != nil {
591 return errors.Errorf("table %q already exists in schema %q", newName, s.proto.Name)
592 }
593
594 // Remove from internal map using old name
595 oldTableID := normalizeNameByCaseSensitivity(oldName, s.isObjectCaseSensitive)
596 delete(s.internalTables, oldTableID)
597
598 // Update the table name in the proto
599 oldTable.proto.Name = newName
600
601 // Add back to internal map using new name
602 newTableID := normalizeNameByCaseSensitivity(newName, s.isObjectCaseSensitive)
603 s.internalTables[newTableID] = oldTable
604
605 return nil
606}
607
608// CreateView creates a new view in the schema.
609// Returns an error if the view already exists.

Callers 2

tidbRenameTableFunction · 0.80
tidbAlterTableFunction · 0.80

Calls 3

GetTableMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected