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

[BUG] MYSQL driver no longer respects safe updates #864

Open
ping-localhost opened this issue Dec 30, 2022 · 5 comments
Open

[BUG] MYSQL driver no longer respects safe updates #864

ping-localhost opened this issue Dec 30, 2022 · 5 comments

Comments

@ping-localhost
Copy link

ping-localhost commented Dec 30, 2022

Describe the Bug

golang-migrate no longer respects safe updates within MySQL.

Steps to Reproduce

  1. Create a database that has SQL_SAFE_UPDATES enabled.
  2. Run any migration which causes the migrations table to be updated.
  3. query := "DELETE FROM `" + m.config.MigrationsTable + "`" will be executed and golang-migrate will error out:

Error 1175: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column in line 0: DELETE FROM schema_migrations

Expected Behavior

I would expect golang-migrate to respect this flag by using an additional WHERE-statement (or by using TRUNCATE).

Migrate Version

github.com/golang-migrate/migrate/v4 v4.15.2

Loaded Source Drivers

iofs (so I can use go:embed)

Loaded Database Drivers

mysql

Go Version

go version go1.19.3 darwin/amd64

Additional context

This does not happen in v4.15.1 as it used TRUNCATE (changed with #656), which is acceptable for safe updating. Might be nice if I, as a user, could select what I want to use?

@ping-localhost ping-localhost changed the title MYSQL driver no longer respects safe updates [BUG] MYSQL driver no longer respects safe updates Jan 2, 2023
@ping-localhost
Copy link
Author

This is still an issue in v4.16.2, is there anything that can be done so safe updates work again?

@emeka
Copy link

emeka commented Apr 10, 2024

Could this be solved by adding a LIMIT clause to the delete instead of moving back to truncate which is not transactional?

@maxmati
Copy link
Contributor

maxmati commented Apr 10, 2024

I made a PR that should solve this issue #1070 while still keeping the DELETE. I've also created tag v4.17.0-safe in our fork which incorporates this change already. It can be used like this: replace github.com/golang-migrate/migrate/v4 v4.17.0 => github.com/certifaction/migrate/v4 v4.17.0-safe

@ping-localhost
Copy link
Author

Could this be solved by adding a LIMIT clause to the delete instead of moving back to truncate which is not transactional?

I've not yet had time to test the proposed change, but if @maxmati can confirm this works, I'll gladly close my MR in favor of #1070 👌

@maxmati
Copy link
Contributor

maxmati commented Apr 11, 2024

Yes this works for me :)

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

No branches or pull requests

3 participants