From 6182d90ef3e0f89bbdd73f8c8c4a051688a54cba Mon Sep 17 00:00:00 2001 From: Adrien Aury <44274230+adrienaury@users.noreply.github.com> Date: Tue, 8 Mar 2022 16:04:53 +0100 Subject: [PATCH] fix(push): truncate impact too many tables (#80) * fix(push): don't touch inactive tables * fix(push): consider only connected tables * fix(push): fix for --table flag * docs: add fix changelog --- CHANGELOG.md | 1 + internal/app/push/cli.go | 18 +++++++++++++----- pkg/id/driver.go | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3910af3..4294fbd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/internal/app/push/cli.go b/internal/app/push/cli.go index 3ffa9902..25f4c22b 100755 --- a/internal/app/push/cli.go +++ b/internal/app/push/cli.go @@ -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) } diff --git a/pkg/id/driver.go b/pkg/id/driver.go index 503c823c..db5180b3 100755 --- a/pkg/id/driver.go +++ b/pkg/id/driver.go @@ -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()) +}