Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate mirror: Bypass no rows error #1309

Merged
merged 9 commits into from
Feb 16, 2024
19 changes: 14 additions & 5 deletions flow/connectors/postgres/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"strconv"
"strings"

Expand Down Expand Up @@ -35,7 +36,7 @@ func (c *PostgresConnector) CheckSourceTables(ctx context.Context,

tableStr := strings.Join(tableArr, ",")
// Check if publication exists
err := c.conn.QueryRow(ctx, "SELECT pubname FROM pg_publication WHERE pubname=$1", pubName).Scan(nil)
err := c.conn.QueryRow(ctx, "SELECT pubname FROM pg_publication WHERE pubname="+QuoteLiteral(pubName)).Scan(nil)
Amogh-Bharadwaj marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
if err == pgx.ErrNoRows {
return fmt.Errorf("publication does not exist: %s", pubName)
Expand Down Expand Up @@ -67,17 +68,25 @@ func (c *PostgresConnector) CheckReplicationPermissions(ctx context.Context, use
}

var replicationRes bool
err := c.conn.QueryRow(ctx, "SELECT rolreplication FROM pg_roles WHERE rolname = $1", username).Scan(&replicationRes)
err := c.conn.QueryRow(ctx, "SELECT rolreplication FROM pg_roles WHERE rolname = "+
QuoteLiteral(username)).Scan(&replicationRes)
if err != nil {
return err
if err == pgx.ErrNoRows {
c.logger.Warn("No rows in pg_roles for user. Skipping rolereplication check",
slog.String("username", username))
} else {
return err
}
}

if !replicationRes {
// RDS case: check pg_settings for rds.logical_replication
var setting string
err := c.conn.QueryRow(ctx, "SELECT setting FROM pg_settings WHERE name = 'rds.logical_replication'").Scan(&setting)
if err != nil || setting != "on" {
return errors.New("postgres user does not have replication role")
if err != pgx.ErrNoRows {
if err != nil || setting != "on" {
return errors.New("postgres user does not have replication role")
}
}
}

Expand Down
Loading