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

fix(database/clickhouse): properly escape database and table name #1004

Closed
wants to merge 1 commit into from

Conversation

jerome-quere
Copy link

Properly escape ClickHouse table and database name when building query.

ClickHouse doc: Escape identifier

@coveralls
Copy link

Coverage Status

coverage: 58.526%. remained the same
when pulling 632ff18 on bodyguard-ai:fix
into 856ea12 on golang-migrate:master.

@TomerGershi
Copy link

This is widely needed! Thank you!

@rotemro
Copy link

rotemro commented Dec 7, 2023

Thanks for the fix! @jerome-quere
@dhui Please approve 🙏

@@ -192,7 +192,7 @@ func (ch *ClickHouse) SetVersion(version int, dirty bool) error {
return err
}

query := "INSERT INTO " + ch.config.MigrationsTable + " (version, dirty, sequence) VALUES (?, ?, ?)"
query := "INSERT INTO `" + ch.config.MigrationsTable + "` (version, dirty, sequence) VALUES (?, ?, ?)"
Copy link
Member

@dhui dhui Dec 20, 2023

Choose a reason for hiding this comment

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

Note, there are still strings that would break this. e.g. if the table or db contained a `
See also: golang/go#18478

EDIT:
You'll see that some db drivers implement this themselves

Copy link
Member

Choose a reason for hiding this comment

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

Just merged another PR (#857) that fixes this

@dhui dhui closed this Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants