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

Method RenameView

backend/store/model/database.go:665–693  ·  view source on GitHub ↗

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

(oldName string, newName string)

Source from the content-addressed store, hash-verified

663// RenameView renames a view in the schema.
664// Returns an error if the old view doesn't exist or new view already exists.
665func (s *SchemaMetadata) RenameView(oldName string, newName string) error {
666 if oldName == newName {
667 return nil
668 }
669
670 // Check if old view exists
671 oldView := s.GetView(oldName)
672 if oldView == nil {
673 return errors.Errorf("view %q does not exist in schema %q", oldName, s.proto.Name)
674 }
675
676 // Check if new view already exists
677 if s.GetView(newName) != nil {
678 return errors.Errorf("view %q already exists in schema %q", newName, s.proto.Name)
679 }
680
681 // Remove from internal map using old name
682 oldViewID := normalizeNameByCaseSensitivity(oldName, s.isObjectCaseSensitive)
683 delete(s.internalViews, oldViewID)
684
685 // Update the view name in the proto
686 oldView.Name = newName
687
688 // Add back to internal map using new name
689 newViewID := normalizeNameByCaseSensitivity(newName, s.isObjectCaseSensitive)
690 s.internalViews[newViewID] = oldView
691
692 return nil
693}
694
695// CreateMaterializedView creates a new materialized view in the schema.
696// Returns an error if the materialized view already exists.

Callers

nothing calls this directly

Calls 3

GetViewMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected