Skip to content

Commit

Permalink
SF QRep: Swap synced at update with alter table rename (#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj authored Mar 12, 2024
1 parent 8583d62 commit 50646c9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions flow/connectors/postgres/qrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,26 @@ func (c *PostgresConnector) ConsolidateQRepPartitions(ctx context.Context, confi
if err != nil {
return fmt.Errorf("failed to drop %s: %v", dstTableName, err)
}
_, err = tx.Exec(ctx, fmt.Sprintf("ALTER TABLE %s RENAME TO %s",
tempTableIdentifier.Sanitize(), QuoteIdentifier(dstSchemaTable.Table)))
if err != nil {
return fmt.Errorf("failed to rename %s to %s: %v",
tempTableIdentifier.Sanitize(), dstTableIdentifier.Sanitize(), err)
}

if config.SyncedAtColName != "" {
updateSyncedAtStmt := fmt.Sprintf(
`UPDATE %s SET %s = CURRENT_TIMESTAMP`,
dstTableIdentifier.Sanitize(),
tempTableIdentifier.Sanitize(),
QuoteIdentifier(config.SyncedAtColName),
)
_, err = tx.Exec(ctx, updateSyncedAtStmt)
if err != nil {
return fmt.Errorf("failed to update synced_at column: %v", err)
}
}

_, err = tx.Exec(ctx, fmt.Sprintf("ALTER TABLE %s RENAME TO %s",
tempTableIdentifier.Sanitize(), QuoteIdentifier(dstSchemaTable.Table)))
if err != nil {
return fmt.Errorf("failed to rename %s to %s: %v",
tempTableIdentifier.Sanitize(), dstTableIdentifier.Sanitize(), err)
}

}

if constraintsHookExists {
Expand Down

0 comments on commit 50646c9

Please sign in to comment.