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 Clickhouse driver to work correctly with v2 #723

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lo00l
Copy link

@lo00l lo00l commented Mar 31, 2022

This PR solves a problem mentioned in #704.

The reason migrating stopped working with Golang Clickhouse driver of 2nd version (github.com/ClickHouse/clickhouse-go/v2) is that it's now required to use prepared statements when inserting values to DB. Currently, this package (github.com/golang-migrate/migrate/v4) doesn't use prepared statements when migrationg Clickhouse. I just added stmt, err := tx.Prepare(query) and now everything works as expected both in 1st and 2nd version of Clickhouse driver.

You can see tests in my repo: https://github.com/lo00l/migrate-test/actions/runs/2072749495

Also this PR introduces similar changes as #697, but in this case tests are not modified.

@coveralls
Copy link

coveralls commented Mar 31, 2022

Coverage Status

Coverage decreased (-0.02%) to 57.784% when pulling 2237947 on lo00l:master into 331a15d on golang-migrate:master.

if _, err := tx.Exec(query, version, bool(dirty), time.Now().UnixNano()); err != nil {
stmt, err := tx.Prepare(query)
if err != nil {
tx.Rollback()

Choose a reason for hiding this comment

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

You could change this to this

if errRollback := tx.Rollback(); errRollback != nil {
			return fmt.Errorf("error during prepare statement %w and rollback %s", err, errRollback.Error())
		}
		return err

@johnatannvmd
Copy link

@lo00l Could you please change your commit.

@dhui Could you please review and approve this PR.

Thanks in advance!

@johnatannvmd
Copy link

@dhui could you please review changes?

image

@lo00l
Copy link
Author

lo00l commented Jul 6, 2022

@dhui Any updates?

I made a fork of this package in my company's private repo, and currently I use replace directive in go.mod file to install correct version of the package. This version is based on my branch. And everything works well, with no issues.

Maybe it's time to merge this PR?

@johnatannvmd
Copy link

Join to the @lo00l, forced to do the same thing. Everything is working as expected.

@zcross
Copy link

zcross commented Aug 5, 2022

Bumping out of interest (thanks to the author/reviewers); I can +1 that I've experienced the problem that motivated this PR and that using this fork solved the problem.

@artur-shafikov
Copy link

I can confirm that these changes fixed this problem
code: 62, message: Cannot parse expression of type Int64 here: ?, ?, ?): While executing ValuesBlockInputFormat in line 0: INSERT INTO schema_migrations (version, dirty, sequence) VALUES (?, ?, ?)

Merge this into master ASAP

@makeavish
Copy link

@dhui Please review this PR

Thanks 🙏

@makeavish
Copy link

@dhui Gentle reminder, please review any of PRs related to clickhouse driver v2

@obalunenko
Copy link

@lo00l please update your PR with master branch 🙏🏿

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.

None yet

7 participants