Skip to content

[db-sync] Escape column name in UPDATE statement #11286

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

Merged
merged 1 commit into from
Jul 11, 2022
Merged

Conversation

andrew-farries
Copy link
Contributor

Description

Escape column names in backquotes when db-sync generates UPDATE statements.

This ensures that db-sync is able to generate these statements for tables having SQL keywords as column names.

Related Issue(s)

Fixes #11265

How to test

Take the db-sync image built on this branch and hot-patch the db-sync image running in staging. See that db-sync runs without error in staging.

Release Notes

NONE

@andrew-farries andrew-farries requested a review from a team July 11, 2022 14:55
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jul 11, 2022
@geropl geropl self-assigned this Jul 11, 2022
@@ -147,7 +147,7 @@ export class TableUpdate {
}

protected getUpdateConditions(row: any): string {
return this.table.primaryKeys.map(pk => `${pk}=${escape(row[pk])}`).concat([`${this.table.timeColumn}<=${escape(row[this.table.timeColumn])}`]).join(" AND ");
return this.table.primaryKeys.map(pk => `${escapeWithBackticks(pk)}=${escape(row[pk])}`).concat([`${this.table.timeColumn}<=${escape(row[this.table.timeColumn])}`]).join(" AND ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this LGTM! 🚀

@roboquat roboquat merged commit f375abc into main Jul 11, 2022
@roboquat roboquat deleted the af/fix-db-sync branch July 11, 2022 15:07
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/XS team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

db-sync fails to sync SSHPublicKeys
3 participants