Skip to content

fix: Add app_id field to the t_component_library table#220

Merged
hexqi merged 4 commits intoopentiny:developfrom
lu-yg:fix/develop
May 21, 2025
Merged

fix: Add app_id field to the t_component_library table#220
hexqi merged 4 commits intoopentiny:developfrom
lu-yg:fix/develop

Conversation

@lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented May 15, 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?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added support for associating an application ID with component libraries. Users can now specify or view the related application ID in relevant component library records.
  • Bug Fixes

    • Improved data handling to ensure the new application ID field is correctly managed during create, update, and query operations.
    • Enhanced user authorization logic to accurately check permissions based on the currently logged-in user.
  • Tests

    • Updated tests to cover the new application ID field in component library entities.

@coderabbitai
Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

A new nullable integer column app_id was added to the t_component_library table in both H2 and MySQL schemas. The ComponentLibrary Java entity and its MyBatis mapper were updated to support this field, integrating it into CRUD operations. The MyMetaObjectHandler was enhanced to fill the "tenantId" field, and related test logic was adjusted accordingly. Additionally, the PageServiceImpl was modified to dynamically obtain the current user ID from the login context instead of using a fixed user ID.

Changes

File(s) Change Summary
app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql
app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql
Added nullable integer column app_id to the t_component_library table definition.
app/src/main/resources/sql/h2/update_all_tables_ddl.sql
app/src/main/resources/sql/mysql/update_all_tables_ddl.sql
Added migration SQL to add nullable integer column app_id to the t_component_library table.
base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java Added private field appId (Integer) with @Schema annotation to the ComponentLibrary class.
base/src/main/resources/mappers/ComponentLibraryMapper.xml Integrated app_id in all relevant CRUD SQL fragments and mappings: base columns, result maps, select, insert, update, and conditionals for ComponentLibrary.
base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java Modified insertFill to include a fill operation for the "tenantId" field using LoginUserContext.
base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java Updated test to expect 6 invocations of hasSetter instead of 5, aligning with the new field.
base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java Changed checkDelete method to retrieve current user ID dynamically from loginUserContext instead of using a hardcoded user ID.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Service
    participant DB

    User->>Service: Create/Update ComponentLibrary (with appId)
    Service->>DB: INSERT/UPDATE t_component_library (includes app_id)
    DB-->>Service: Acknowledge
    Service-->>User: Operation result

    User->>Service: Query ComponentLibrary
    Service->>DB: SELECT ... FROM t_component_library (includes app_id)
    DB-->>Service: Result with app_id
    Service-->>User: ComponentLibrary data (with appId)
Loading

Poem

In tables and code, a field now appears,
app_id joins in, with no doubts or fears.
Mappers and models, all in a line,
SQL and Java, their duties align.
The tests counted six, not just five—
With every new field, our code comes alive!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e7ea549 and 6f25fdb.

📒 Files selected for processing (1)
  • base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java (1 hunks)
🔇 Additional comments (1)
base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java (1)

533-533: Good fix for using dynamic user ID!

Replacing the hardcoded user ID with the dynamic retrieval from loginUserContext.getLoginUserId() improves security by ensuring authorization checks happen against the actual logged-in user.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch fix/develop
  • Post Copyable Unit Tests in Comment

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 auto-generate unit tests to generate unit tests 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.

Copy link

@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: 2

♻️ Duplicate comments (1)
app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql (1)

654-654: Duplicate: consider adding a foreign key and index for app_id
See the H2 schema review above for recommendations on enforcing referential integrity and improving query performance by indexing app_id.

🧹 Nitpick comments (5)
base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java (1)

44-44: Expanded automatic field filling to include tenantId

The addition of tenantId to the automatic field filling mechanism is a good enhancement that ensures consistent tenant data across entities. This change aligns with the existing pattern in the handler class.

Consider adding a comment explaining why tenantId is being handled differently with fillStrategy instead of setFieldValByName like the other fields.

app/src/main/resources/sql/mysql/update_all_tables_ddl.sql (1)

31-31: New app_id column added to t_component_library table

This change adds the app_id field to the component library table in the MySQL database, consistent with the H2 schema update.

Ensure that similar changes are made to any other database scripts in the codebase, such as initial schema creation scripts, to maintain consistency across all environments.

app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql (1)

654-654: Consider adding a foreign key and index for app_id
Right now app_id is a plain nullable column; enforcing referential integrity with a foreign key constraint referencing t_app(id) and adding an index on app_id can improve data integrity and query performance.

base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java (1)

47-48: Explicitly map appId with @TableField
Consider adding @TableField("app_id") above the appId field to make the column-to-property mapping explicit and guard against future naming-strategy changes.

base/src/main/resources/mappers/ComponentLibraryMapper.xml (1)

10-12: Wrap app_id in backticks for consistency
Other column names like name, public, and others are backticked; wrapping app_id as `app_id` ensures consistent escaping and avoids potential case-sensitivity or reserved-word issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d840667 and 6dbfe2d.

📒 Files selected for processing (8)
  • app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql (1 hunks)
  • app/src/main/resources/sql/h2/update_all_tables_ddl.sql (1 hunks)
  • app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql (1 hunks)
  • app/src/main/resources/sql/mysql/update_all_tables_ddl.sql (1 hunks)
  • base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java (1 hunks)
  • base/src/main/resources/mappers/ComponentLibraryMapper.xml (8 hunks)
  • base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java (1 hunks)
🔇 Additional comments (6)
base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java (1)

39-39: Test verification correctly updated for new field

The updated assertion correctly accounts for the additional hasSetter call introduced by the new tenantId fill operation.

base/src/main/resources/mappers/ComponentLibraryMapper.xml (5)

22-24: Conditional filter for appId is correct
The added <if> block cleanly integrates app_id filtering, matching the pattern used for other fields.


95-97: Update clause for app_id is correctly added
The <if> block ensures app_id is only updated when non-null, consistent with other conditional set clauses.


165-165: Result mapping for app_id is correct
Mapping the app_id column to the appId property aligns with the entity and naming conventions in ComponentLibrary.


228-228: Select clause includes app_id
The CL.app_id projection is properly inserted into the select list, ensuring the field is loaded in queryAllComponentLibrary.


384-385: Insert statement updated to include app_id
Both the column list and the corresponding value placeholder for app_id (#{appId}) are correctly added, preserving alignment with the entity and table schema.

Also applies to: 409-410

@hexqi hexqi merged commit bd015fe into opentiny:develop May 21, 2025
1 check passed
@lu-yg lu-yg deleted the fix/develop branch June 10, 2025 01:09
lu-yg added a commit to lu-yg/tiny-engine-backend-java that referenced this pull request Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants