From bfdb0391aca0030e94f8f8872b1ab0f1956c51b0 Mon Sep 17 00:00:00 2001 From: Yevgeny Pats <16490766+yevgenypats@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:46:13 +0200 Subject: [PATCH 1/3] fix: Make sure _cq_id unique across all dest plugins --- plugins/destination/plugin.go | 2 ++ schema/meta.go | 3 +++ schema/type_test.go | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/destination/plugin.go b/plugins/destination/plugin.go index 3387339bbd..0cc27136df 100644 --- a/plugins/destination/plugin.go +++ b/plugins/destination/plugin.go @@ -285,6 +285,8 @@ func SetDestinationManagedCqColumns(tables []*schema.Table) { for _, table := range tables { table.OverwriteOrAddColumn(&schema.CqSyncTimeColumn) table.OverwriteOrAddColumn(&schema.CqSourceNameColumn) + // This is for backward compatiblity for sources that didn't update the SDK yet + table.OverwriteOrAddColumn(&schema.CqIDColumn) SetDestinationManagedCqColumns(table.Relations) } diff --git a/schema/meta.go b/schema/meta.go index 50a61697c6..0d99ec7724 100644 --- a/schema/meta.go +++ b/schema/meta.go @@ -16,6 +16,9 @@ var CqIDColumn = Column{ Type: TypeUUID, Description: "Internal CQ ID of the row", Resolver: cqUUIDResolver(), + CreationOptions: ColumnCreationOptions{ + NotNull: true, + }, } var CqParentIDColumn = Column{ Name: "_cq_parent_id", diff --git a/schema/type_test.go b/schema/type_test.go index 4fbde7e7b6..712a13d502 100644 --- a/schema/type_test.go +++ b/schema/type_test.go @@ -3,7 +3,6 @@ package schema import ( "encoding/json" "errors" - "fmt" "net" "strings" "testing" @@ -59,7 +58,6 @@ func TestCQTypesMarshal(t *testing.T) { &Bool{Bool: true, Status: Present}, } b, err := json.Marshal(cqTypes) - fmt.Println(string(b)) if err != nil { t.Fatal(err) } From aee8b4164310470e002bb4515bac6ef4113020ee Mon Sep 17 00:00:00 2001 From: Yevgeny Pats <16490766+yevgenypats@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:47:50 +0200 Subject: [PATCH 2/3] lint fix --- plugins/destination/plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/destination/plugin.go b/plugins/destination/plugin.go index 0cc27136df..2d846a80c9 100644 --- a/plugins/destination/plugin.go +++ b/plugins/destination/plugin.go @@ -285,7 +285,7 @@ func SetDestinationManagedCqColumns(tables []*schema.Table) { for _, table := range tables { table.OverwriteOrAddColumn(&schema.CqSyncTimeColumn) table.OverwriteOrAddColumn(&schema.CqSourceNameColumn) - // This is for backward compatiblity for sources that didn't update the SDK yet + // This is for backward compatibility for sources that didn't update the SDK yet table.OverwriteOrAddColumn(&schema.CqIDColumn) SetDestinationManagedCqColumns(table.Relations) From 758509cf2bb75ee5fb9e53a36fb26ad2ffc35a5e Mon Sep 17 00:00:00 2001 From: Yevgeny Pats <16490766+yevgenypats@users.noreply.github.com> Date: Mon, 13 Feb 2023 17:58:02 +0200 Subject: [PATCH 3/3] fix tests --- plugins/destination/plugin.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/destination/plugin.go b/plugins/destination/plugin.go index 2d846a80c9..5c3c0995d4 100644 --- a/plugins/destination/plugin.go +++ b/plugins/destination/plugin.go @@ -186,6 +186,7 @@ func (p *Plugin) Init(ctx context.Context, logger zerolog.Logger, spec specs.Des // we implement all DestinationClient functions so we can hook into pre-post behavior func (p *Plugin) Migrate(ctx context.Context, tables schema.Tables) error { SetDestinationManagedCqColumns(tables) + setCqIDNotNullColumnForTables(tables) return p.client.Migrate(ctx, tables) } @@ -285,9 +286,20 @@ func SetDestinationManagedCqColumns(tables []*schema.Table) { for _, table := range tables { table.OverwriteOrAddColumn(&schema.CqSyncTimeColumn) table.OverwriteOrAddColumn(&schema.CqSourceNameColumn) - // This is for backward compatibility for sources that didn't update the SDK yet - table.OverwriteOrAddColumn(&schema.CqIDColumn) - SetDestinationManagedCqColumns(table.Relations) } } + +// this is for backward compatibility for sources that didn't update the SDK yet +// TODO: remove this in the future once all sources have updated the SDK +func setCqIDNotNullColumnForTables(tables []*schema.Table) { + for _, table := range tables { + for i, c := range table.Columns { + if c.Name == schema.CqIDColumn.Name { + table.Columns[i].CreationOptions.NotNull = true + return + } + } + setCqIDNotNullColumnForTables(table.Relations) + } +}