Skip to content

fix: fixed material generation and database connection for components#1215

Merged
chilingling merged 1 commit intoopentiny:developfrom
Ljhhhhhh:fix-material
Mar 17, 2025
Merged

fix: fixed material generation and database connection for components#1215
chilingling merged 1 commit intoopentiny:developfrom
Ljhhhhhh:fix-material

Conversation

@Ljhhhhhh
Copy link
Contributor

@Ljhhhhhh Ljhhhhhh commented Mar 12, 2025

English | 简体中文

PR

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

What is the current behavior?

引入的第三方组件无法在出码、预览中正常使用

What is the new behavior?

引入的第三方组件在出码、预览中可正常使用

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Improved component data management with revised database interactions.
    • Updated metadata and history tracking to ensure more accurate recording and enhanced consistency of component records.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

Walkthrough

The pull request updates the database interaction logic in the scripts/connection.mjs file. It modifies the component schema by changing table names and field identifiers, adjusts SQL queries, and updates method names. Specifically, the table reference is updated from 'user_components' to 't_component', and the material history ID is changed from 639 to 1. The method formerly known as relationMaterialHistory is renamed to relationMaterialBlockHistory with a revised query, and a new method relationMaterialHistory is introduced. Updates in the insertComponent and initDB methods further reinforce these database schema changes.

Changes

File Summary of Changes
scripts/connection.mjs - Updated table name ('user_components''t_component') and materialHistoryId (6391).
- Renamed method: relationMaterialHistoryrelationMaterialBlockHistory with updated SQL query.
- Added new method relationMaterialHistory using a revised table and query structure.
- Modified insertComponent to replace tenant, createBy, and updatedBy with component_metadata, library_id, tenant_id, renter_id, site_id, created_by, and last_updated_by, and added name_en to the columns.
- Updated initDB query from using component to name_en.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant Conn as MysqlConnection
    participant DB as Database
    App->>Conn: Call insertComponent(data)
    Conn->>DB: Execute INSERT into t_component (with updated columns)
    DB-->>Conn: Confirmation/Inserted row
    Conn-->>App: Return result
Loading
sequenceDiagram
    participant App as Application
    participant Conn as MysqlConnection
    participant DB as Database
    App->>Conn: Call relationMaterialHistory(id)
    Conn->>DB: Execute query on r_material_history_component table
    DB-->>Conn: Return query results
    Conn-->>App: Return data
Loading

Possibly related PRs

Suggested labels

bug, refactor-main

Suggested reviewers

  • chilingling
  • hexqi

Poem

I'm a little rabbit with a code-hop beat,
Skipping through queries with a nimble feat.
Tables renamed and methods renewed,
Database dances in lines so true.
Happy hops, my code's complete! 🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 bug Something isn't working label Mar 12, 2025
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: 3

🧹 Nitpick comments (1)
scripts/connection.mjs (1)

205-205: Consider removing the deprecated method entirely.
You've marked relationMaterialBlockHistory as deprecated. If no external files still depend on it, removing it can reduce noise in the codebase.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66a6d00 and 45aaf27.

📒 Files selected for processing (1)
  • scripts/connection.mjs (6 hunks)
🔇 Additional comments (4)
scripts/connection.mjs (4)

18-18: Ensure consistency between table name and helper methods.
You've updated componentsTableName to 't_component', but all of the helper methods (like createUserComponentsTable) are still called "user components." Verify that you are referencing the correct table and that your migrations align with the new name.


20-20: Confirm the hard-coded material ID.
materialHistoryId is changed to 1. Confirm this aligns with the records in r_material_history_component or that it won’t cause insert/lookup failures.


208-217: Check references to old table in relationMaterialBlockHistory.
This deprecated method still references material_histories_components__user_components_mhs. Ensure no new features require the old table or remove it if it’s truly obsolete.


219-231: New method referencing updated table.
relationMaterialHistory uses r_material_history_component, which looks consistent with your new schema. Make sure all callers are updated to use this method instead of the deprecated one.

@chilingling chilingling merged commit 54af598 into opentiny:develop Mar 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants