chore(db): introduce db.Session and db.EngineMigration interfaces#37746
Conversation
…actor migration and model packages Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/d71872e6-87e8-4c92-abf4-73e0632a85eb Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/f1c5b8fc-bc58-4cb2-a722-9fab296ed0e9 Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
5b098a0 to
2435cbe
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces two new abstractions in models/db:
db.Session— an interface over*xorm.Session(extendingdb.EnginewithAnd/Begin/Close/Commit/IsInTx/Rollback/Engine).db.EngineMigration— an interface over*xorm.Enginefor migration code (extendingdb.EnginewithDB/DBMetas/Dialect/DropTables/NewSession/QueryInterface/SetMapper/SyncWithOptions/TableInfo/TableName/Close).
It then mechanically replaces direct *xorm.Engine and *xorm.Session usages with these interfaces throughout migrations, models, services, and routers. As a consequence, db.SetSessionPagination now returns the Session interface (instead of *xorm.Session), and call sites that previously did sess = db.SetSessionPagination(...) are simplified to call it for side effects (xorm Limit mutates the session in place).
Changes:
- Add
db.Sessionanddb.EngineMigrationinterfaces inmodels/db/engine.go. - Migrate every migration function signature (
v70..v334) and the migration framework (models/migrations/migrations.go) to usedb.EngineMigration; switch oneInsertOnetoInsert. - Update model/service/router call sites to use the new interfaces and to discard the now-Session-typed return of
db.SetSessionPagination.
Reviewed changes
Copilot reviewed 300 out of 300 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| models/db/engine.go, engine_init.go, list.go, collation.go | Adds Session/EngineMigration interfaces; SetSessionPagination returns Session; InitEngineWithMigration and collation helpers take EngineMigration. |
| models/migrations/migrations.go, base/db.go, migrationtest/tests.go | Migration runner/helpers/test helpers retyped to EngineMigration; InsertOne replaced with Insert. |
| models/migrations/v1_/v.go (and v326_test.go, v286_test.go) | All ~140 migration functions retyped from *xorm.Engine to db.EngineMigration (and *xorm.Session to db.Session where applicable). |
| models/activities/.go, models/git/.go, models/issues/.go, models/organization/.go, models/packages/**/.go, models/repo/.go, models/user/*.go | Function signatures retyped to db.Session; db.SetSessionPagination calls no longer reassign the return value. |
| services/versioned_migration/migration.go, routers/common/db.go, cmd/doctor.go | Migration entrypoints retyped to db.EngineMigration. |
| tests/integration/migration-test/migration_test.go | Test helpers/types retyped to db.EngineMigration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bircni
left a comment
There was a problem hiding this comment.
thats good but will break a lot of upcoming PRs when they merge
* 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
No description provided.