From 7a85cf3e1a92532f8161d9ce0e601fd7e838fa82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Sun, 25 Jun 2023 13:20:46 +0200 Subject: [PATCH] Change alteration merge to remove all found duplicates Before it terminated too quickly so it would incloude half of the duplicates. This would cause a problem if we added multiple bits with the same ident (nested record values for example). --- server/pkg/dal/alteration.go | 6 ++++-- server/pkg/dal/alteration_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/pkg/dal/alteration.go b/server/pkg/dal/alteration.go index ade366b06..42a265361 100644 --- a/server/pkg/dal/alteration.go +++ b/server/pkg/dal/alteration.go @@ -96,10 +96,12 @@ func (aa AlterationSet) Merge(bb AlterationSet) (cc AlterationSet) { } if a.compare(*aux[j]) { + if !found { + cc = append(cc, aux[j]) + } + seen[j] = true found = true - cc = append(cc, aux[j]) - break } } diff --git a/server/pkg/dal/alteration_test.go b/server/pkg/dal/alteration_test.go index fde6aa32a..8d7c8e0dc 100644 --- a/server/pkg/dal/alteration_test.go +++ b/server/pkg/dal/alteration_test.go @@ -89,6 +89,14 @@ func TestMerge(t *testing.T) { }, }, }, + &Alteration{ + AttributeAdd: &AttributeAdd{ + Attr: &Attribute{ + Ident: "foo", + Type: &TypeJSON{Nullable: false}, + }, + }, + }, }, cc: AlterationSet{ &Alteration{