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)
| 663 | // RenameView renames a view in the schema. |
| 664 | // Returns an error if the old view doesn't exist or new view already exists. |
| 665 | func (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. |
nothing calls this directly
no test coverage detected