MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RenameTable

Method RenameTable

core/rootvalue.go:794–829  ·  view source on GitHub ↗

RenameTable implements the interface doltdb.RootValue.

(ctx context.Context, oldName, newName doltdb.TableName)

Source from the content-addressed store, hash-verified

792
793// RenameTable implements the interface doltdb.RootValue.
794func (root *RootValue) RenameTable(ctx context.Context, oldName, newName doltdb.TableName) (doltdb.RootValue, error) {
795 _, rawOldID, objID, err := rootobject.ResolveName(ctx, root, oldName)
796 if err != nil {
797 return nil, err
798 }
799 if objID == objinterface.RootObjectID_None {
800 newStorage, err := root.st.EditTablesMap(ctx, root.vrw, root.ns, []storage.TableEdit{{OldName: oldName, Name: newName}})
801 if err != nil {
802 return nil, err
803 }
804 newRoot := root.withStorage(newStorage)
805
806 collection, err := sequences.LoadSequences(ctx, newRoot)
807 if err != nil {
808 return nil, err
809 }
810 seqs, err := collection.GetSequencesWithTable(ctx, oldName)
811 if err != nil {
812 return nil, err
813 }
814 for _, seq := range seqs {
815 seq.OwnerTable = id.NewTable(seq.OwnerTable.SchemaName(), newName.Name)
816 }
817 return collection.UpdateRoot(ctx, newRoot)
818 } else {
819 coll, err := rootobject.LoadCollection(ctx, root, objID)
820 if err != nil {
821 return nil, err
822 }
823 rawNewID := coll.TableNameToID(newName)
824 if err = coll.RenameRootObject(ctx, rawOldID, rawNewID); err != nil {
825 return nil, err
826 }
827 return coll.UpdateRoot(ctx, root)
828 }
829}
830
831// ResolveRootValue implements the interface doltdb.RootValue.
832func (root *RootValue) ResolveRootValue(ctx context.Context) (doltdb.RootValue, error) {

Callers

nothing calls this directly

Calls 11

withStorageMethod · 0.95
ResolveNameFunction · 0.92
LoadSequencesFunction · 0.92
NewTableFunction · 0.92
LoadCollectionFunction · 0.92
EditTablesMapMethod · 0.80
GetSequencesWithTableMethod · 0.80
UpdateRootMethod · 0.65
TableNameToIDMethod · 0.65
RenameRootObjectMethod · 0.65
SchemaNameMethod · 0.45

Tested by

no test coverage detected