From 8c8fdc918569a04dbfb779f1134d273ffc1d9b1e Mon Sep 17 00:00:00 2001 From: Ben Bernays Date: Wed, 31 Jan 2024 11:29:09 -0600 Subject: [PATCH] fix: Handle PrimaryKeyComponents in packaging (#1503) Handle PrimaryKeyComponents in packaging --- serve/package.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/serve/package.go b/serve/package.go index 41dbdc1624..8fcfff8b46 100644 --- a/serve/package.go +++ b/serve/package.go @@ -19,6 +19,7 @@ import ( cloudquery_api "github.com/cloudquery/cloudquery-api-go" "github.com/cloudquery/plugin-sdk/v4/plugin" + "github.com/cloudquery/plugin-sdk/v4/schema" "github.com/spf13/cobra" ) @@ -80,8 +81,11 @@ func (s *PluginServe) writeTablesJSON(ctx context.Context, dir string) error { Type: column.Type.String(), IncrementalKey: column.IncrementalKey, NotNull: column.NotNull, - PrimaryKey: column.PrimaryKey, - Unique: column.Unique, + // PrimaryKey Will be set to true Under the following conditions: + // 1. If the column is a `PrimaryKeyComponent` + // 2. If the column is a `PrimaryKey` and both of the following are true column name is NOT `_cq_id` and there are other columns that are a PrimaryKeyComponent + PrimaryKey: (column.PrimaryKey && !(column.Name == schema.CqIDColumn.Name && len(table.PrimaryKeyComponents()) > 0)) || column.PrimaryKeyComponent, + Unique: column.Unique, }) } tablesToEncode = append(tablesToEncode, cloudquery_api.PluginTableCreate{