RenameTable implements the interface doltdb.RootValue.
(ctx context.Context, oldName, newName doltdb.TableName)
| 792 | |
| 793 | // RenameTable implements the interface doltdb.RootValue. |
| 794 | func (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. |
| 832 | func (root *RootValue) ResolveRootValue(ctx context.Context) (doltdb.RootValue, error) { |
nothing calls this directly
no test coverage detected