Skip to content

fix: Modify the default values of table fields and page API #218

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

Merged
merged 113 commits into from
May 14, 2025

Conversation

lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented May 14, 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 a post-save extension point for pages, allowing custom actions after a page is created or updated.
  • Database Changes

    • The tenant_id field is now optional (nullable) in multiple tables across both H2 and MySQL databases.
  • Chores

    • Adjusted automated field population to no longer set certain fields by default during insert operations.
  • Tests

    • Updated tests to reflect changes in field handling during insert operations.

lu-yg and others added 30 commits December 26, 2024 00:15
Copy link

coderabbitai bot commented May 14, 2025

Walkthrough

This update modifies database schema files for both H2 and MySQL by making the tenant_id column nullable across numerous tables. Corresponding migration scripts are also updated. In the application layer, a new PostSaveHook interface is introduced and integrated into the page service to allow post-save actions. Some field assignments and related test expectations are removed from the meta object handler.

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
Removed not null constraint from tenant_id in many tables, making it nullable.
app/src/main/resources/sql/h2/update_all_tables_ddl.sql
app/src/main/resources/sql/mysql/update_all_tables_ddl.sql
Added/updated ALTER TABLE statements to allow tenant_id to be nullable in many tables.
base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java Removed assignments to "tenantId", "renterId", and "siteId" fields in the insertFill method.
base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java Added optional autowired PostSaveHook and invoked its afterSave method after page save/update operations.
base/src/main/java/com/tinyengine/it/service/extend/PostSaveHook.java Introduced new PostSaveHook interface with afterSave(Page page) method.
base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java Adjusted test to expect 5 (instead of 8) calls to hasSetter in testInsertFill.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PageServiceImpl
    participant PostSaveHook (optional)

    Client->>PageServiceImpl: createPage() / updatePage()
    PageServiceImpl->>PageServiceImpl: Save Page & PageHistory
    alt postSaveHook present
        PageServiceImpl->>PostSaveHook (optional): afterSave(Page)
    end
    PageServiceImpl-->>Client: Return result
Loading

Poem

In tables wide, the tenant’s key
Now may be blank, and roam free.
A hook now hops in after save—
To lend a paw, post-page wave.
Old fields removed, tests trimmed with care,
The schema’s lighter—fresh spring air!
🐇✨

Tip

⚡️ 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.

✨ 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.

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: 0

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

25-26: Duplicate: nullable tenant_id in H2 schema creation
This mirrors the change in the MySQL schema—tenant_id is now nullable in every table. Please refer to the comments on the MySQL script to ensure consistency in application handling, index semantics, and documentation.

Also applies to: 46-47, 52-53, 102-103, 123-124, 143-144, 161-162, 201-202, 240-241, 276-277, 306-307, 336-337, 367-368, 394-395, 433-434, 504-505, 541-542, 567-568, 625-626

🧹 Nitpick comments (2)
app/src/main/resources/sql/h2/update_all_tables_ddl.sql (2)

8-8: Add rationale for making publish_url nullable
Allowing publish_url to be NULL is fine for backward compatibility, but consider adding a brief inline comment above this DDL change to explain why it’s now optional (e.g., legacy records or deferred publishing). This will help future maintainers understand the intent.


10-29: Verify application behavior with NULL tenant_id
The NOT NULL constraint on tenant_id is being dropped across many tables. Please ensure:

  1. The Java data-access layer and any ORM mappings properly handle tenant_id IS NULL.
  2. Queries and unique indexes still behave as expected when tenant_id is NULL (MySQL/ H2 treat NULLs as distinct).
  3. New unit/integration tests cover both null and non-null tenant scenarios.
    Would you like assistance generating those tests or verifying index behavior?
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c6b8c14 and 0e44141.

📒 Files selected for processing (8)
  • app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql (20 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 (20 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 (0 hunks)
  • base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java (4 hunks)
  • base/src/main/java/com/tinyengine/it/service/extend/PostSaveHook.java (1 hunks)
  • base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java
🔇 Additional comments (8)
base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java (1)

39-39: Test updated to match implementation changes.

The test expectation has been correctly reduced from 8 to 5 calls to hasSetter, which aligns with the removal of "tenantId", "renterId", and "siteId" field filling in the MyMetaObjectHandler class.

base/src/main/java/com/tinyengine/it/service/extend/PostSaveHook.java (1)

13-29: Well-designed extension point for post-save operations.

This interface provides a clean extension mechanism for actions that need to occur after saving a page. The interface follows single responsibility principle with appropriate documentation.

base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java (4)

47-47: LGTM: Appropriate import for the new hook.


140-144: Well-implemented optional dependency injection.

The PostSaveHook is properly autowired with required = false, making it optional and preventing application startup failures if no implementation is provided.


284-286: Good defensive programming when invoking the hook.

The implementation checks for null before invoking the hook, ensuring no NullPointerException occurs when no hook implementation is provided.


378-380: Consistent implementation in both save operations.

The hook invocation is consistently implemented in both create and update operations, maintaining code symmetry.

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

10-29:

❓ Verification inconclusive

Verify business impact of making tenant_id nullable.

The changes correctly modify the tenant_id column across multiple tables to be nullable. This is a significant schema change that aligns with the removal of tenant_id auto-filling in MyMetaObjectHandler.

However, this may have business logic implications:

  1. Are there any downstream processes that assume tenant_id is always present?
  2. Does this affect multi-tenancy security or data isolation?
  3. Will existing code handle null tenant_id values properly?

🏁 Script executed:

#!/bin/bash
# Search for places where tenant_id is used without null checks

echo "Searching for code that might assume tenant_id is non-null:"
echo "--------------------------------------------------------"

# Find queries that filter by tenant_id without checking for null
echo "SQL queries or conditions using tenant_id:"
rg -A 2 -B 2 "tenant_id\s*=|tenant_id\s*==|\.eq\(\s*[\"']tenant_id[\"']\s*," --type java

# Find places where tenant_id is accessed directly (might need null checks)
echo "Direct tenant_id access that might need null checks:"
rg -A 2 -B 2 "\.getTenantId\(\)" --type java

# Check service implementations for tenant_id usage
echo "Service implementations using tenant_id:"
rg -A 5 -B 5 "tenant_id" --type java --glob "*ServiceImpl.java"

Length of output: 756


🏁 Script executed:

#!/bin/bash
echo "Searching for 'tenantId' in Java sources:"
rg -n "tenantId" --type java

echo
echo "Searching for QueryWrapper.eq or eq methods with TenantId arguments:"
rg -n "eq\s*\(\s*.*TenantId" --type java

echo
echo "Searching for @Column annotation referencing tenant_id:"
rg -n "@Column.*tenant_id" --type java

echo
echo "Searching for 'tenantId' in XML mapper files:"
rg -n "tenantId" -g "*.xml"

Length of output: 14461


Verify multi-tenancy behavior when tenant_id is null
Now that tenant_id is nullable and auto-filling has been removed, all MyBatis mappers will skip the AND tenant_id = … clause whenever tenantId is null or empty—potentially returning data across all tenants. Please confirm that this aligns with your business and security requirements:

• In *.xml mappers (e.g. PageMapper.xml, UserMapper.xml, etc.), each <if test="tenantId!=null and tenantId!=''"> block will be bypassed for null values, dropping tenant isolation.
• There is no additional null‐check logic in Java (no eq("tenantId", …) calls nor direct getTenantId() usages that enforce non-null).
• Tests (e.g. MyMetaObjectHandlerTest) and entity mappings (via @Schema and <result column="tenant_id" property="tenantId"/>) will still function, but may now propagate null tenantId into DTOs and responses.

• Do downstream services, APIs or UIs expect tenantId to always be present?
• Should queries with null tenantId default to an empty result set or raise an error instead of returning all rows?
• Are there any security audits or monitoring you need to add around null tenancy contexts?

Please review and adjust the SQL conditions or service logic as needed to maintain proper data isolation.

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

25-26: Make tenant_id nullable in all MySQL create scripts
You’ve removed the NOT NULL constraint on tenant_id for every table. Please verify:

  • All migration paths and the application layer expect and handle NULL tenant IDs correctly.
  • Unique indexes that include tenant_id still enforce uniqueness as intended in MySQL (multiple NULLs allowed).
  • Documentation, entity definitions, and test suites are updated to reflect that tenant_id can now be NULL.

Also applies to: 52-53, 102-103, 123-124, 143-144, 161-162, 201-202, 240-241, 276-277, 306-307, 336-337, 367-368, 394-395, 433-434, 504-505, 541-542, 567-568, 625-626

@hexqi hexqi merged commit d840667 into opentiny:develop May 14, 2025
2 checks passed
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