fix(mirror): correct instance clause in verify

This commit is contained in:
adlerhurst 2024-07-22 11:22:01 +02:00
parent e009ed9fe4
commit 4814881626
2 changed files with 29 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"strings"
"sync"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -91,10 +92,34 @@ func instanceClause() string {
if isSystem {
return "WHERE instance_id <> ''"
}
for i := range instanceIDs {
instanceIDs[i] = "'" + instanceIDs[i] + "'"
}
stringifyInstances()
// COPY does not allow parameters so we need to set them directly
return "WHERE instance_id IN (" + strings.Join(instanceIDs, ", ") + ")"
}
var customTableInstanceColumns = map[string]string{
"projections.system_features": "",
"system.encryption_keys": "",
"projections.instances": "id",
}
func instanceClauseForVerify(tableName string) string {
if column, ok := customTableInstanceColumns[tableName]; ok {
if column == "" {
return ""
}
if isSystem {
return "WHERE " + column + " <> ''"
}
stringifyInstances()
return "WHERE " + column + "IN (" + strings.Join(instanceIDs, ", ") + ")"
}
return instanceClause()
}
var stringifyInstances = sync.OnceFunc(func() {
for i := range instanceIDs {
instanceIDs[i] = "'" + instanceIDs[i] + "'"
}
})

View File

@ -103,7 +103,7 @@ func countEntries(ctx context.Context, client *database.DB, table string) (count
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, instanceClauseForVerify(table)),
)
logging.WithFields("table", table, "db", client.DatabaseName()).OnError(err).Error("unable to count")