-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 migration file names #25735
Fix migration file names #25735
Conversation
The file names of the migrations and the comments in `models/migrations/migrations.go` disagree on the version number. For example: // v259 -> v260 NewMigration("Convert scoped access tokens", v1_20.ConvertScopedAccessTokens), ...but the file containing `v1_20.ConvertScopedAccessTokens` is called `v1_20/v259.go`. Checking the `version` table indicates that the comments are correct and the file names are wrong. git does not explicitly track renames. This causes a problem when we're renaming many files. If a directory had e.g. 3 files in it: v1_50/v500.go v1_50/v501.go v1_50/v502.go and we incremented their filenames like so: v1_50/v500.go -> v1_50/v501.go v1_50/v501.go -> v1_50/v502.go v1_50/v502.go -> v1_50/v503.go git would say that we deleted `v500.go`, changed `v501.go` and `v502.go`, and created a new file, `v503.go`. To work around this, this change is split into two commits. This first one increments all the file names and moves the files to a new directory. git correctly detects these as renames. The next commit will move them all back. This is the command used for this commit (cwd: `models/migrations`): for x in */v*.go do mkdir -p $(dirname $x).new v=$(echo $x | sed -e 's!.*/v\([0-9]*\).*!\1!g') git mv $x $(dirname $x).new/v$(echo $x | sed -e 's@.*/v\([0-9]*\)\(.*\)@'$(($v+1))'\2@g') done
This is the second part of this mass renaming. See previous commit for rationale. This is the command used for this commit (cwd: `models/migrations`): for x in *.new/v*.go do git mv $x $(basename $(dirname $x) .new)/ done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the individual commits.
Out of curiosity, does Gitea display the changes only as renames or like Github does?
the pull diff is hard to read :/ |
Maybe we can rename v259.go -> 260.go so that git can recognize the rename. And next PR we can also rename back if we need that. |
The root problem is "how to understand the 'version' and the comment". For example:
Before:
After:
|
I also agree with using some tricks like "v259.go -> 260.go" (or |
My suggestion is If one day we get |
If you look at the two individual commits you only see renames, so it's fine. |
I don't think it's fine, if the final merged commit cannot recognize the rename, it can be annoying when git blame. |
Agree with lunny and wolfogre. When this PR gets "squashed" into main branch, we should make sure there is a clear commit history. Although these two separate commits are clear one by one, but, when they get squashed, the commit history will be a mess. So, there are some suggestions for "only one clear commit".
|
Alternative GitLab does the same: https://gitlab.com/gitlab-org/gitlab/-/tree/master/db/migrate |
Hmm or make an exemption and dont squashmerge? |
I also have asked so, but at that time, in discord discussion, maintainers explained that "Only use the v123.go, to make sure the filename conflicts for different PRs, that's the conflict-based workflow". I am not sure whether maintainers have new ideas about this topic nowadays. |
@wxiaoguang I wrote https://github.com/techknowlogick/xormigrate to 1. backport migrations, 2. prevent conflicts from migrates having the same name, and 3. a cleaner developer experience. |
I think there should be some better solutions than this change, this change's "squash" merge would make the commit unreadable. |
Alternatively, we could just get rid of the individual comments in |
IMO the comments should be kept, that's the only way (at the moment, by reading code) to know the "version number" of a migration step. |
Stale and a lot of conflicts. Feel free to reopen if some comments (like #25735 (comment)) are addressed. It needs a clear "squahed" result. |
-> Refactor the DB migration system slightly #32344 |
The file names of the migrations and the comments in
models/migrations/migrations.go
disagree on the version number.For example:
...but the file containing
v1_20.ConvertScopedAccessTokens
is calledv1_20/v259.go
.Checking the
version
table indicates that the comments are correctand the file names are wrong.
This PR fixes the filenames. It's spread over two commits in an attempt
to make git understand that they're renames. See individual commit
messages for more detail.