From a09c772b034c5490249d8d61dd7ed4ea73c72f50 Mon Sep 17 00:00:00 2001 From: chris-1o Date: Tue, 12 Nov 2024 17:03:41 +0100 Subject: [PATCH] fix(mirror): Fix instance_id check for tables without (#8852) # Which Problems Are Solved Fixes 'column "instance_id" does not exist' errors from #8558. # How the Problems Are Solved The instanceClause / WHERE clause in the query for the respective tables is excluded. I have successfully created a mirror with this change. --- cmd/mirror/verify.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/mirror/verify.go b/cmd/mirror/verify.go index 7b90ad89aa..68c927d091 100644 --- a/cmd/mirror/verify.go +++ b/cmd/mirror/verify.go @@ -5,13 +5,16 @@ import ( "database/sql" _ "embed" "fmt" + "slices" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/zitadel/logging" + cryptoDatabase "github.com/zitadel/zitadel/internal/crypto/database" "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/database/dialect" + "github.com/zitadel/zitadel/internal/query/projection" ) func verifyCmd() *cobra.Command { @@ -98,12 +101,22 @@ func getViews(ctx context.Context, dest *database.DB, schema string) (tables []s } func countEntries(ctx context.Context, client *database.DB, table string) (count int) { + instanceClause := instanceClause() + noInstanceIDColumn := []string{ + projection.InstanceProjectionTable, + projection.SystemFeatureTable, + cryptoDatabase.EncryptionKeysTable, + } + if slices.Contains(noInstanceIDColumn, table) { + instanceClause = "" + } + err := client.QueryRowContext( ctx, func(r *sql.Row) error { return r.Scan(&count) }, - fmt.Sprintf("SELECT COUNT(*) FROM %s %s", table, instanceClause()), + fmt.Sprintf("SELECT COUNT(*) FROM %s %s", table, instanceClause), ) logging.WithFields("table", table, "db", client.DatabaseName()).OnError(err).Error("unable to count")