fix(migrations): preserve unique constraints in v334 sync#37743
Conversation
The partial ActionRunner struct in AddCancellingSupportToActionRunner omits the UNIQUE on token_hash, so xorm's SyncWithOptions would drop that constraint to make the live table match. Set IgnoreConstrains so existing unique constraints are left alone, matching v333. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
@lunny what's your plan to avoid such problems in the future? I have pointed it out at least 3 times. |
maybe adding a lint for it or any other checks? |
It might be a new sync function like Sync(struct, is_drop_index, is_drop_unqie) could avoid some possible wrong usage. |
It's difficult to know it want to create a new table or add a new column. |
No, the callers all clearly know
It's just a new dirty patch, just more messy. |
With #37668 it will be possible to write golangci-lint plugins with full AST access. BTW still looking for approval there. |
Even if you have full AST access, what can you do for it? What are the rules in your mind to "lint" for these cases? |
|
Right, the lint does not see the DB structure. The better fix would probably be to have xorm have safer defaults, should check how other ORMs do it. |
* origin/main: fix: Allow direct commits for unprotected files with push restrictions (go-gitea#37657) chore: Conventional adjustments (go-gitea#37677) chore(db): introduce db.Session and db.EngineMigration interfaces (go-gitea#37746) fix(migrations): preserve unique constraints in v334 sync (go-gitea#37743) feat(web): also display PR counts in repo list (go-gitea#37739)
* origin/main: (39 commits) fix: Add missed token scope checking (go-gitea#37735) chore: Use giteabot instead of backporter (go-gitea#37422) fix: Allow direct commits for unprotected files with push restrictions (go-gitea#37657) chore: Conventional adjustments (go-gitea#37677) chore(db): introduce db.Session and db.EngineMigration interfaces (go-gitea#37746) fix(migrations): preserve unique constraints in v334 sync (go-gitea#37743) feat(web): also display PR counts in repo list (go-gitea#37739) feat: execute post run cleanup when workflow is cancelled (go-gitea#37275) fix(actions): wrong assumption that run id always >= job id (go-gitea#37737) fix(icon): use repo-forked icon to display forks count (go-gitea#37731) fix(oauth): strengthen PKCE validation and refresh token replay protection (go-gitea#37706) fix(web): enforce token scopes on raw, media, and attachment downloads (go-gitea#37698) feat: Add bypass allowlist for branch protection (go-gitea#36514) refactor(glob): use strings.Builder for regexp compilation (go-gitea#37730) feat(oauth): Support AWS Cognito OAuth2 provider (go-gitea#37607) feat: Add default PR branch update style setting (go-gitea#37410) refactor: move `workflowpattern` into `modules/actions` (go-gitea#37717) ci: add `zizmor` to `lint-actions` (go-gitea#37720) chore(doctor): remove four obsolete doctor check implementations (go-gitea#37728) chore(renovate): enable dockerfile manager (go-gitea#37719) ... # Conflicts: # modules/globallock/locker_test.go
The truncated
ActionRunnerstruct inAddCancellingSupportToActionRunnerdeclares only the newHasCancellingSupportcolumn. When xorm'sSyncWithOptionscompares it against the liveaction_runnertable, every index/constraint absent from the local struct is a candidate for removal.Walking xorm v1.3.11 sync.go:250-266:
IndexTypeindices skip the drop whenIgnoreIndices || IgnoreDropIndices— already covered.UniqueTypeindices skip the drop only whenIgnoreConstrains— not set in feat: execute post run cleanup when workflow is cancelled #37275, so the existingUNIQUEontoken_hash(and any other uniques) would be dropped on upgrade.Adding
IgnoreConstrains: truematches v333's pattern and preserves the existing unique constraints. Spotted by @wxiaoguang in #37275 (comment).This PR was written with the help of Claude Opus 4.7