RemoveTables implements the interface doltdb.RootValue.
( ctx context.Context, skipFKHandling bool, allowDroppingFKReferenced bool, originalTables ...doltdb.TableName, )
| 628 | |
| 629 | // RemoveTables implements the interface doltdb.RootValue. |
| 630 | func (root *RootValue) RemoveTables( |
| 631 | ctx context.Context, |
| 632 | skipFKHandling bool, |
| 633 | allowDroppingFKReferenced bool, |
| 634 | originalTables ...doltdb.TableName, |
| 635 | ) (doltdb.RootValue, error) { |
| 636 | if len(originalTables) == 0 { |
| 637 | return root, nil |
| 638 | } |
| 639 | |
| 640 | tableMaps := make(map[string]storage.RootTableMap) |
| 641 | deletedObjIds := make(map[objinterface.RootObjectID]struct{}) |
| 642 | var tables []doltdb.TableName |
| 643 | var rootObjNames []struct { |
| 644 | rawID id.Id |
| 645 | objID objinterface.RootObjectID |
| 646 | } |
| 647 | for _, name := range originalTables { |
| 648 | // Split into tables and root objects |
| 649 | tableMap, ok := tableMaps[name.Schema] |
| 650 | if !ok { |
| 651 | var err error |
| 652 | tableMap, err = root.getTableMap(ctx, name.Schema) |
| 653 | if err != nil { |
| 654 | return nil, err |
| 655 | } |
| 656 | tableMaps[name.Schema] = tableMap |
| 657 | } |
| 658 | tableHash, err := tableMap.Get(ctx, name.Name) |
| 659 | if err != nil { |
| 660 | return nil, err |
| 661 | } |
| 662 | if !tableHash.IsEmpty() { |
| 663 | tables = append(tables, name) |
| 664 | continue |
| 665 | } |
| 666 | // Table wasn't in the table map, so we'll check our root objects |
| 667 | _, rawID, objID, err := rootobject.ResolveName(ctx, root, name) |
| 668 | if err != nil { |
| 669 | return nil, err |
| 670 | } |
| 671 | if objID == objinterface.RootObjectID_None { |
| 672 | return nil, errors.Errorf("%w: '%s'", doltdb.ErrTableNotFound, name) |
| 673 | } |
| 674 | rootObjNames = append(rootObjNames, struct { |
| 675 | rawID id.Id |
| 676 | objID objinterface.RootObjectID |
| 677 | }{rawID: rawID, objID: objID}) |
| 678 | deletedObjIds[objID] = struct{}{} |
| 679 | } |
| 680 | newRoot := root |
| 681 | |
| 682 | // First we'll handle regular table names |
| 683 | if len(tables) > 0 { |
| 684 | edits := make([]storage.TableEdit, len(tables)) |
| 685 | for i, name := range tables { |
| 686 | edits[i].Name = name |
| 687 | } |
nothing calls this directly
no test coverage detected