Describe the feature
At the moment, the order of which columns are migrated during AutoMigrate is non-deterministic.
I'm using copyist to test our migrations, which when run in "recording" mode, intercepts all SQL operations and saves them to a file. Then you can run the tests in "playback" mode and if the queries run do not match those which were recorded, then the test fails. This is great when you want to run a full test suite and you don't want to have a database running locally.
I'm creating a feature request, rather than a bug, since I don't think this would have been an intended feature unless someone else has specifically requested it.
Motivation
Tests are good, tests without having to stand up a full database instance are even better.
Essentially, this for loop on line 99 iterates in a non-deterministic way, meaning sometimes my migrations migrate columns in one order, then in another run in another order: https://github.com/go-gorm/gorm/blob/2aca96d1474967da11bac81a58db9c97bd7bdcac/migrator/migrator.go#L96-L102
My request is to build a slice of column names, sort them, and then iterate over that slice instead.
Related Issues
Couldn't find any related issues.
Comment From: dan-j
Hey @jinzhu, any thoughts on the feature request? I don't mind contributing a PR providing it's something you're willing to accept a PR for. Thanks
Comment From: github-actions[bot]
This issue has been automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days
Comment From: dan-j
Hey @jinzhu, is this something you would accept a PR for? I don't want to waste time working on it if it's not going to be accepted.
Comment From: dan-j
Just pinging this @jinzhu, come back across this issue today. Any thoughts on my solution?
Comment From: jinzhu
Hi @dan-j
Sorry for the delay, maybe you can range the fields with schema.DBNames, a PR would be appreciated , thank you.