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.
This commit is contained in:
chris-1o 2024-11-12 17:03:41 +01:00 committed by GitHub
parent 778b4041ca
commit a09c772b03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,13 +5,16 @@ import (
"database/sql" "database/sql"
_ "embed" _ "embed"
"fmt" "fmt"
"slices"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/zitadel/logging" "github.com/zitadel/logging"
cryptoDatabase "github.com/zitadel/zitadel/internal/crypto/database"
"github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/database/dialect" "github.com/zitadel/zitadel/internal/database/dialect"
"github.com/zitadel/zitadel/internal/query/projection"
) )
func verifyCmd() *cobra.Command { 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) { 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( err := client.QueryRowContext(
ctx, ctx,
func(r *sql.Row) error { func(r *sql.Row) error {
return r.Scan(&count) 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") logging.WithFields("table", table, "db", client.DatabaseName()).OnError(err).Error("unable to count")