Skip to content

chore(db): introduce db.Session and db.EngineMigration interfaces#37746

Merged
wxiaoguang merged 3 commits into
mainfrom
copilot/refactor-db-engine-interfaces
May 17, 2026
Merged

chore(db): introduce db.Session and db.EngineMigration interfaces#37746
wxiaoguang merged 3 commits into
mainfrom
copilot/refactor-db-engine-interfaces

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

No description provided.

…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>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 17, 2026
Copilot stopped work on behalf of wxiaoguang due to an error May 17, 2026 18:58
Copilot AI requested a review from wxiaoguang May 17, 2026 18:58
@wxiaoguang wxiaoguang changed the title feat(db): introduce db.Session and db.EngineMigration interfaces to abstract xorm types chore(db): introduce db.Session and db.EngineMigration interfaces to abstract xorm types May 17, 2026
@wxiaoguang wxiaoguang marked this pull request as ready for review May 17, 2026 19:00
Copilot stopped work on behalf of wxiaoguang due to an error May 17, 2026 19:06
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 17, 2026
@wxiaoguang wxiaoguang force-pushed the copilot/refactor-db-engine-interfaces branch from 5b098a0 to 2435cbe Compare May 17, 2026 19:22
@wxiaoguang wxiaoguang changed the title chore(db): introduce db.Session and db.EngineMigration interfaces to abstract xorm types chore(db): introduce db.Session and db.EngineMigration interfaces May 17, 2026
@wxiaoguang wxiaoguang requested a review from Copilot May 17, 2026 19:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces two new abstractions in models/db:

  • db.Session — an interface over *xorm.Session (extending db.Engine with And/Begin/Close/Commit/IsInTx/Rollback/Engine).
  • db.EngineMigration — an interface over *xorm.Engine for migration code (extending db.Engine with DB/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.Session and db.EngineMigration interfaces in models/db/engine.go.
  • Migrate every migration function signature (v70..v334) and the migration framework (models/migrations/migrations.go) to use db.EngineMigration; switch one InsertOne to Insert.
  • 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.

Copy link
Copy Markdown
Member

@bircni bircni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats good but will break a lot of upcoming PRs when they merge

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 17, 2026
@wxiaoguang wxiaoguang merged commit 94e3482 into main May 17, 2026
30 checks passed
@GiteaBot GiteaBot added this to the 1.27.0 milestone May 17, 2026
@wxiaoguang wxiaoguang deleted the copilot/refactor-db-engine-interfaces branch May 17, 2026 19:56
silverwind added a commit to silverwind/gitea that referenced this pull request May 17, 2026
* 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)
silverwind added a commit to silverwind/gitea that referenced this pull request May 18, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants