Skip to content

feat(mockServer): mockserver support custom database path#1501

Merged
chilingling merged 2 commits intoopentiny:developfrom
hexqi:feat/support-project-db
Jul 3, 2025
Merged

feat(mockServer): mockserver support custom database path#1501
chilingling merged 2 commits intoopentiny:developfrom
hexqi:feat/support-project-db

Conversation

@hexqi
Copy link
Collaborator

@hexqi hexqi commented Jul 3, 2025

English | 简体中文

PR

mockserver 支持配置自定义数据库路径

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

  1. mockserver中pages.db存在冗余数据;默认的createVm页面数据,在设计器中编辑时会提示名字需要大写开头,校验不通过

当前使用CLI创建的项目中启动后使用的是node_modules中的mock server数据库,数据存储在node_modules中只能在本地有效,在团队开发场景中无法通过git进行协作共享或者版本管理,无法进行持久化保存。
因此增加mockserver的自定义能力,提供数据库目录的配置,用户可以配置到项目目录中,进行持久化或通过git管理。

What is the current behavior?

  1. 删除冗余数据;页面重命名:createVm --> CreateVm
  2. 需要自定义场景,用户可以通过命令 给mockerserver 传递DATABASE_PATH环境变量指定配置的数据库目录,例如启动script可以做如下修改:
-- "serve:mock": "node node_modules/@opentiny/tiny-engine-mock/dist/app.js"
++ "serve:mock": "cross-env DATABASE_PATH=./mock/database/ node node_modules/@opentiny/tiny-engine-mock/dist/app.js"

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor

    • Improved database file path handling by introducing a centralized utility for retrieving database paths, replacing previous hardcoded path resolutions.
  • New Features

    • Added a new utility function for consistent database path retrieval across the application.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

A new utility function, getDatabasePath, was added to centralize the logic for resolving database file paths. Several service modules were updated to use this function instead of directly using the Node.js path module and hardcoded path resolution. No changes to logic or exported entities occurred beyond this refactoring.

Changes

Files Change Summary
mockServer/src/services/block.js
mockServer/src/services/blockCategory.js
mockServer/src/services/blockGroup.js
mockServer/src/services/pages.js
Replaced direct use of Node.js path module and hardcoded path resolution with the new getDatabasePath utility function for NeDB datastore initialization.
mockServer/src/tool/Common.js Added import of Node.js path module and introduced the exported getDatabasePath(fileName) function to centralize database path resolution.

Poem

In the burrows of code where data does dwell,
A new path emerges, as rabbits can tell.
No more hardcoded trails, just a single way—
With getDatabasePath, we all hop and play!
Centralized and tidy, our warren feels right,
As we nibble on carrots and code through the night. 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the enhancement New feature or request label Jul 3, 2025
@hexqi hexqi force-pushed the feat/support-project-db branch from c6d8e4f to 0f8d721 Compare July 3, 2025 09:06
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f473753 and 0f8d721.

⛔ Files ignored due to path filters (1)
  • mockServer/src/database/pages.db is excluded by !**/*.db
📒 Files selected for processing (5)
  • mockServer/src/services/block.js (1 hunks)
  • mockServer/src/services/blockCategory.js (1 hunks)
  • mockServer/src/services/blockGroup.js (1 hunks)
  • mockServer/src/services/pages.js (1 hunks)
  • mockServer/src/tool/Common.js (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/RenderMain.ts:82-88
Timestamp: 2025-01-14T08:50:50.226Z
Learning: For PR #1011, the focus is on resolving conflicts and migrating code, with architectural improvements deferred for future PRs.
mockServer/src/services/pages.js (3)
Learnt from: yy-wow
PR: opentiny/tiny-engine#940
File: packages/canvas/DesignCanvas/src/importMap.js:51-51
Timestamp: 2025-01-13T03:46:13.817Z
Learning: The `getImportMapData` function in `packages/canvas/DesignCanvas/src/importMap.js` has default parameter handling that initializes `canvasDeps` with empty arrays for `scripts` and `styles`, making additional null checks unnecessary.
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/common/composable/index.js:3-3
Timestamp: 2024-10-30T02:10:38.028Z
Learning: 在 `packages/common/composable` 目录中,`HttpService` 模块位于 `./http/index.js`,而不是 `./http.js`。
Learnt from: gene9831
PR: opentiny/tiny-engine#1011
File: packages/canvas/route-bar/src/CanvasRouteBar.vue:23-25
Timestamp: 2025-01-14T06:45:03.521Z
Learning: The global base service (`META_SERVICE.GlobalService`) guarantees that `baseInfo` will always contain a `pageId` property.
mockServer/src/services/block.js (1)
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/toolbars/generate-code/src/http.js:39-40
Timestamp: 2024-10-30T02:38:05.165Z
Learning: In the function `fetchBlockSchema` in `packages/toolbars/generate-code/src/http.js`, input validation and error handling for the `blockName` parameter are handled by the user elsewhere, so it's acceptable not to perform parameter validation or URL encoding in this function within this codebase.
mockServer/src/services/blockGroup.js (1)
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/toolbars/generate-code/src/http.js:39-40
Timestamp: 2024-10-30T02:38:05.165Z
Learning: In the function `fetchBlockSchema` in `packages/toolbars/generate-code/src/http.js`, input validation and error handling for the `blockName` parameter are handled by the user elsewhere, so it's acceptable not to perform parameter validation or URL encoding in this function within this codebase.
mockServer/src/services/blockCategory.js (1)
Learnt from: yy-wow
PR: opentiny/tiny-engine#886
File: packages/toolbars/generate-code/src/http.js:39-40
Timestamp: 2024-10-30T02:38:05.165Z
Learning: In the function `fetchBlockSchema` in `packages/toolbars/generate-code/src/http.js`, input validation and error handling for the `blockName` parameter are handled by the user elsewhere, so it's acceptable not to perform parameter validation or URL encoding in this function within this codebase.
🧬 Code Graph Analysis (5)
mockServer/src/services/pages.js (1)
mockServer/src/tool/Common.js (2)
  • getDatabasePath (79-82)
  • getDatabasePath (79-82)
mockServer/src/services/block.js (1)
mockServer/src/tool/Common.js (2)
  • getDatabasePath (79-82)
  • getDatabasePath (79-82)
mockServer/src/services/blockGroup.js (1)
mockServer/src/tool/Common.js (2)
  • getDatabasePath (79-82)
  • getDatabasePath (79-82)
mockServer/src/tool/Common.js (1)
scripts/copyToVscode.js (1)
  • path (13-13)
mockServer/src/services/blockCategory.js (1)
mockServer/src/tool/Common.js (2)
  • getDatabasePath (79-82)
  • getDatabasePath (79-82)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (9)
mockServer/src/tool/Common.js (1)

13-13: Good addition of path module import.

The ES6 import syntax is consistent with the module system being used.

mockServer/src/services/block.js (2)

13-13: Excellent refactoring to use centralized path resolution.

The import change correctly replaces direct path handling with the new utility function.


18-18: Consistent implementation of database path resolution.

The usage of getDatabasePath('blocks.db') is consistent with the centralized approach and maintains the same database filename.

mockServer/src/services/blockCategory.js (2)

13-13: Consistent refactoring pattern applied.

The import change correctly adopts the new centralized database path resolution utility.


19-19: Proper usage of the utility function.

The getDatabasePath('blockCategories.db') call maintains the correct database filename while enabling customizable path resolution.

mockServer/src/services/blockGroup.js (2)

13-13: Consistent adoption of centralized path resolution.

The import statement correctly uses the new utility function from the Common module.


19-19: Correct implementation of database path resolution.

The getDatabasePath('blockGroups.db') usage maintains the database filename while enabling the new configurable path feature.

mockServer/src/services/pages.js (2)

14-14: Successful completion of the refactoring pattern.

The import change correctly adopts the centralized database path resolution, completing the consistent implementation across all service files.


19-19: Proper implementation of the new database path feature.

The getDatabasePath('pages.db') call correctly implements the customizable database path feature while preserving the database filename.

@chilingling chilingling merged commit 9ba6c82 into opentiny:develop Jul 3, 2025
3 checks passed
hexqi added a commit that referenced this pull request Jul 3, 2025
* fix: remove useless data and fix pagename
* feat: mockserver support custom dbpath
This was referenced Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants