Open ping-localhost opened 1 year ago
This is still an issue in v4.16.2, is there anything that can be done so safe updates work again?
Could this be solved by adding a LIMIT clause to the delete instead of moving back to truncate which is not transactional?
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
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 👌
Yes this works for me :)
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
Just tried this locally and it did not actually resolve my issue:
2024-06-12T15:30:24.396+0200 INFO migrations loggers/migration.go:21 Start buffering 1/u initialize_schema
2024/06/12 15:30:24 Caught panic:
Error 1175 (HY000): 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` LIMIT 1
Describe the Bug
golang-migrate
no longer respects safe updates within MySQL.Steps to Reproduce
SQL_SAFE_UPDATES
enabled.query := "DELETE FROM `" + m.config.MigrationsTable + "`"
will be executed andgolang-migrate
will error out:Expected Behavior
I would expect
golang-migrate
to respect this flag by using an additionalWHERE
-statement (or by usingTRUNCATE
).Migrate Version
github.com/golang-migrate/migrate/v4 v4.15.2
Loaded Source Drivers
iofs
(so I can usego: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 https://github.com/golang-migrate/migrate/pull/656), which is acceptable for safe updating. Might be nice if I, as a user, could select what I want to use?