Skip to content
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

♻️ refactor: refactor db core #7245

Merged
merged 2 commits into from
Mar 31, 2025
Merged

♻️ refactor: refactor db core #7245

merged 2 commits into from
Mar 31, 2025

Conversation

arvinxx
Copy link
Contributor

@arvinxx arvinxx commented Mar 31, 2025

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • 📝 docs
  • 🔨 chore

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

@arvinxx arvinxx requested a review from Copilot March 31, 2025 09:49
Copy link

vercel bot commented Mar 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat-database ✅ Ready (Inspect) Visit Preview Mar 31, 2025 10:37am
lobe-chat-desktop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 10:37am
lobe-chat-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 10:37am

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 31, 2025
@lobehubbot
Copy link
Member

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

@Copilot 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 refactors the database core by updating import paths and centralizing database instance retrieval. Key changes include:

  • Updating test files to use the new getTestDBInstance location within '@/database/core/dbForTest'.
  • Refactoring the server database export to come from a new core module (db-adaptor).
  • Adjusting relative import paths in core and test files for consistency.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/database/server/models/tests/user.test.ts Updated import path for getTestDBInstance.
src/database/server/models/tests/nextauth.test.ts Updated import path for getTestDBInstance.
src/database/server/index.ts Refactored serverDB export to use the new db-adaptor module.
src/database/repositories/dataImporter/deprecated/tests/index.test.ts Updated import path for getTestDBInstance.
src/database/models/tests/session.test.ts Updated import path for getTestDBInstance.
src/database/models/tests/_util.ts Updated import path for getTestDBInstance; changed const export.
src/database/models/tests/_test_template.ts Switched to use getTestDB from the local _util module.
src/database/core/web-server.ts Adjusted DB instance type and import paths; removed unused export.
src/database/core/dbForTest.ts Adjusted relative path for schemas import.
src/database/core/db-adaptor.ts Introduced new db-adaptor module to export the serverDB instance.
scripts/migrateServerDB/index.ts Updated serverDB import path to match the new structure.
Comments suppressed due to low confidence (1)

src/database/core/db-adaptor.ts:1

  • [nitpick] The file name 'db-adaptor.ts' uses an unconventional spelling. Consider renaming it to 'db-adapter.ts' for clarity and to align with common conventions.
// import { isDesktop } from '@/const/version';

Copy link
Contributor

gru-agent bot commented Mar 31, 2025

TestGru Assignment

Summary

Link CommitId Status Reason
Detail f3f53c4 🚫 Skipped No files need to be tested {"scripts/migrateServerDB/index.ts":"no test value","src/database/core/db-adaptor.ts":"no test value","src/database/core/dbForTest.ts":"no test value","src/database/core/web-server.ts":"no test value","src/database/models/tests/_test_template.ts":"no test value","src/database/models/tests/_util.ts":"no test value","src/database/models/tests/session.test.ts":"no test value","src/database/repositories/dataImporter/deprecated/tests/index.test.ts":"no test value","src/database/server/index.ts":"no test value","src/database/server/models/tests/nextauth.test.ts":"no test value","src/database/server/models/tests/user.test.ts":"target file(src/database/server/models/tests/user.test.ts) not in work scope \n include: src/utils,src/server,src/database,src/services,src/store,packages//src/ \n exclude: node_modules,/*.test.ts,/.test.tsx,**/.spec.ts,/*.spec.tsx,/.d.ts,**/.test.js,**/*.spec.js,src/database/server"}

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.86%. Comparing base (f831d86) to head (fc40492).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7245   +/-   ##
=======================================
  Coverage   89.86%   89.86%           
=======================================
  Files         749      750    +1     
  Lines       53896    53897    +1     
  Branches     5134     5134           
=======================================
+ Hits        48433    48434    +1     
  Misses       5463     5463           
Flag Coverage Δ
app 89.86% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lobehubbot
Copy link
Member

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

github-actions bot pushed a commit that referenced this pull request Mar 31, 2025
### [Version&nbsp;1.77.4](v1.77.3...v1.77.4)
<sup>Released on **2025-03-31**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor db core.

#### 💄 Styles

- **misc**: Update branding.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Refactor db core, closes [#7245](#7245) ([5c71db6](5c71db6))

#### Styles

* **misc**: Update branding, closes [#7224](#7224) ([481cab0](481cab0))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 1.77.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Apr 1, 2025
### [Version&nbsp;1.117.2](v1.117.1...v1.117.2)
<sup>Released on **2025-04-01**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor db core.

#### 💄 Styles

- **misc**: Update branding.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Refactor db core, closes [lobehub#7245](https://github.com/bentwnghk/lobe-chat/issues/7245) ([5c71db6](5c71db6))

#### Styles

* **misc**: Update branding, closes [lobehub#7224](https://github.com/bentwnghk/lobe-chat/issues/7224) ([481cab0](481cab0))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants