Skip to content

fix: [#840] DB cache is not reset when fresh orm#1322

Merged
hwbrzzl merged 1 commit intomasterfrom
bowen/#840-1
Dec 29, 2025
Merged

fix: [#840] DB cache is not reset when fresh orm#1322
hwbrzzl merged 1 commit intomasterfrom
bowen/#840-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Dec 29, 2025

📑 Description

Closes goravel/goravel#840

This pull request introduces an improvement to the database connection handling by adding a mechanism to reset GORM connections, and integrates this reset into the ORM's Fresh method. The changes also include a minor import update.

Database connection management improvements:

  • Added a new ResetConnections function to database/driver/gorm.go that safely clears the internal map of GORM connections, allowing for a clean reset of database connections.
  • Updated the Fresh method in Orm (database/orm/orm.go) to call driver.ResetConnections(), ensuring that all GORM connections are reset when refreshing the ORM state.

Codebase maintenance:

  • Added an import for github.com/goravel/framework/database/driver in database/orm/orm.go to support the new connection reset functionality.

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings December 29, 2025 03:37
@hwbrzzl hwbrzzl requested a review from a team as a code owner December 29, 2025 03:37
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.95%. Comparing base (eb07027) to head (d944fe8).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1322   +/-   ##
=======================================
  Coverage   69.95%   69.95%           
=======================================
  Files         282      282           
  Lines       16653    16653           
=======================================
  Hits        11649    11649           
  Misses       4516     4516           
  Partials      488      488           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
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 pull request addresses issue #840 by adding a mechanism to reset the database connection cache when the ORM's Fresh method is called. The implementation migrates from a regular map to sync.Map for storing connections and introduces a new ResetConnections function.

Key changes:

  • Introduced ResetConnections() function to clear all cached GORM database connections
  • Modified connection storage from map[string]*gorm.DB to sync.Map
  • Updated Orm.Fresh() to call driver.ResetConnections() for proper cache clearing

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
database/driver/gorm.go Migrated connectionToDB to sync.Map and added ResetConnections function to clear all cached database connections
database/orm/orm.go Added import for database/driver package and integrated driver.ResetConnections() call into Fresh method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hwbrzzl hwbrzzl merged commit 6018934 into master Dec 29, 2025
20 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#840-1 branch December 29, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] 刷新 orm 后数据库驱动仍为旧驱动的问题

2 participants