Skip to content

Commit

Permalink
fix(push): truncate impact too many tables (#80)
Browse files Browse the repository at this point in the history
* fix(push): don't touch inactive tables

* fix(push): consider only connected tables

* fix(push): fix for --table flag

* docs: add fix changelog
  • Loading branch information
adrienaury authored Mar 8, 2022
1 parent 14d1006 commit 6182d90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Types of changes
- `Added` New command to count lines in tables
- `Fixed` limit keyword on DB2 dialect
- `Fixed` Push truncate respect child/parent constraint order
- `Fixed` Push truncate will trigger only for attainable tables in the ingress descriptor - tables that are cut out will not be truncated

## [1.10.0]

Expand Down
18 changes: 13 additions & 5 deletions internal/app/push/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,21 @@ func (c idToPushConverter) getRelation(name string) push.Relation {
)
}

func (c idToPushConverter) getPlan(id id.IngressDescriptor) push.Plan {
func (c idToPushConverter) getPlan(idesc id.IngressDescriptor) push.Plan {
relations := []push.Relation{}

for idx := uint(0); idx < id.Relations().Len(); idx++ {
rel := id.Relations().Relation(idx)
relations = append(relations, c.getRelation(rel.Name()))
activeTables, err := id.GetActiveTables(idesc)
if err != nil {
activeTables = id.NewTableList([]id.Table{idesc.StartTable()})
}

return push.NewPlan(c.getTable(id.StartTable().Name()), relations)
for idx := uint(0); idx < idesc.Relations().Len(); idx++ {
rel := idesc.Relations().Relation(idx)
if (activeTables.Contains(rel.Child().Name()) && rel.LookUpChild()) ||
(activeTables.Contains(rel.Parent().Name()) && rel.LookUpParent()) {
relations = append(relations, c.getRelation(rel.Name()))
}
}

return push.NewPlan(c.getTable(idesc.StartTable().Name()), relations)
}
6 changes: 6 additions & 0 deletions pkg/id/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,9 @@ func Export(storage Storage, exporter Exporter) *Error {

return nil
}

// GetActiveTables returns list of tables that are activated (part of the connected graph)
func GetActiveTables(id IngressDescriptor) (TableList, *Error) {
g := newGraph(id.Relations())
return g.findConnectedTables(id.StartTable().Name())
}

0 comments on commit 6182d90

Please sign in to comment.